A. 国际旅行Ⅰ
标题:
思绪:
因为题意上每个国家可以相互到达,以是只需要排序,输出第k小的值就可以了。
AC代码:
- #include<bits/stdc++.h>
- #define int long long
- #define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
- using namespace std;
- int a[1010];
- signed main()
- {
- IOS
- int n,m,q,u,v,k;
- cin>>n>>m>>q;
- for(int i=0;i<n;i++)
- cin>>a[i];
- for(int i=1;i<=m;i++)
- {
- cin>>u>>v;
- }
- sort(a,a+n);
- for(int i=1;i<=q;i++)
- {
- cin>>k;
- cout<<a[k-1]<<'\n';
- }
- }
复制代码 D.A*BBBB
标题:
思绪:
因为数据范围特殊大,假如用高精乘的话会时间超限,但是标题里面说b的每一位数字都是一样的,以是就把该数字题出来,后面都是1*1,只需要用a乘一个个位数,然后再错位相加。
AC代码:
- #include<bits/stdc++.h>
- #define int long long
- #define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
- using namespace std;
- typedef pair<int,int> PII;
- const int N=2e6+20;
- int a[N],ans[N],num[N],b[N];
- signed main()
- {
- IOS
- int t;
- cin>>t;
- while(t--)
- {
- memset(a,0,sizeof(a));
- string s1,s2;
- cin>>s1>>s2;
- reverse(s1.begin(),s1.end());
- int n=s1.size();
- for(int i=0;i<n;i++)
- {
- b[i]=s1[i]-'0';
- a[i]+=b[i]*(s2[0]-'0');
- a[i+1]+=a[i]/10;
- a[i]%=10;
- // a[i]*=(s2[0]-'0');
- // if(a[i]>=10)
- // {
- // a[i+1]+=a[i]/10;
- // a[i]%=10;
- // }
- }
- // for(int i=0;i<n;i++)
- // {
- // if(a[i]>=10)
- // {
- // a[i+1]+=a[i]/10;
- // a[i]%=10;
- // }
- // }
- if(a[n]==0) n--;
- reverse(a,a+n+1);
- int m=s2.size();
- ans[0]=a[0];
- for(int i=1;i<=n;i++)
- {
- ans[i]=ans[i-1]+a[i];
- }
- int r=-1,l=-m-1;
- int ss=n+m-1;
- for(int i=0;i<=ss;i++)
- {
- r++;
- l++;
- int rr,ll;
- if(r>n) rr=ans[n];
- else rr=ans[r];
- if(l<0) ll=0;
- else ll=ans[l];
- num[i]=rr-ll;
- }
- for(int i=ss;i>=1;i--)
- {
- if(num[i]>=10)
- {
- num[i-1]+=num[i]/10;
- num[i]%=10;
- }
- }
- int dd=0;
- for(int i=0;i<=ss;i++)
- {
- if(num[i]==0&&dd==0&&i!=ss) continue;
- dd=1;
- cout<<num[i];
- }
- cout<<'\n';
- }
- }
复制代码 F. 水灵灵的小学弟
标题:
思绪:
一开始一位是个博弈题,刚想开写,发现两个人的字母缩写相同直接输出就可以了。
AC代码:
- #include<bits/stdc++.h>
- #define int long long
- #define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
- using namespace std;
- signed main()
- {
- IOS
- int t;
- cin>>t;
- while(t--)
- {
- int a,b;
- cin>>a>>b;
- cout<<"DHY"<<'\n';
- }
- }
复制代码 H.狼狼的备忘录
标题:
思绪:
一道模仿题,用了一个map里面套set,假如mp[id]的大小为空的话,就往里面存,否则,遍历这个set,假如mp[id]中有比该字符串长的字符串,就需要判断该字符串是否为厥后缀,遍历完后假如不是mp[id]任何一个的字符串,就存入里面;假如该字符比前面已存入的长,就要遍历这个set,看谁是该字符串的后缀,删掉。最后从头输出map。
AC代码:
- #include<bits/stdc++.h>
- #define int long long
- #define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
- using namespace std;
- signed main()
- {
- IOS
-
- int n;
- cin>>n;
- map<string,set<string> > mp;
- for(int i=0;i<n;i++)
- {
- string id;int op;
- cin>>id>>op;
- while(op--)
- {
- string x;
- cin>>x;
- if(mp[id].empty())
- mp[id].insert(x);
- else
- {
- int flag=1;
- vector<string> q;
- for(auto tt:mp[id])
- {
- if(tt.size()>=x.size())
- {
- int k=tt.rfind(x);
- if(k!=-1)
- {
- if(k+x.size()==tt.size())
- flag=0;
- }
-
- }
- else
- {
- int k=x.rfind(tt);
- if(k!=-1)
- {
- if(k+tt.size()==x.size())
- q.push_back(tt);
- }
- }
- }
- if(flag) mp[id].insert(x);
- if(!q.empty())
- {
- for(auto ss:q) mp[id].erase(ss);
- }
- }
- }
- }
- cout<<mp.size()<<'\n';
- for(auto i:mp)
- {
- cout<<i.first<<" "<<i.second.size()<<" ";
- for(auto j:i.second)
- cout<<j<<" ";
- cout<<'\n';
- }
-
- }
复制代码 I.重生之zbk要拿回属于他的统统
标题:
思绪:
暴力遍历一遍就可以了。
AC代码:
- #include<bits/stdc++.h>
- #define int long long
- #define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
- using namespace std;
- signed main()
- {
- IOS
- int n,t=0;
- cin>>n;
- string s;
- cin>>s;
- for(int i=0;i<n;i++)
- {
- //cout<<s[i]<<" ";
- if(s[i]=='c')
- {
- if(s[i+1]=='h'&&s[i+2]=='u'&&s[i+3]=='a'&&s[i+4]=='n')
- {
- t++;
- s[i]='s';
- s[i+1]='s';
- s[i+2]='s';
- s[i+3]='s';
- s[i+4]='s';
- }
- }
- }
- cout<<t<<'\n';
- }
复制代码 J. 这是签到
标题:
思绪:
数据范围特殊小,我直接纯暴力写的,根据下面给的33的公式,推出来4,5的,直接暴力给a了。
根据33的行列式可以得出,最闭幕果是主对角线对应的乘积减去副对角线对应的乘积的和。好比从左上出发最长的正对角线对应的是从右上出发最长的正对角线相减;左上的正对角线右边的一个对角线加上左下对应右上的正对角线右边的一个对角线加上左上,依次类推,可以得出4,5的公式。
AC代码:
- #include<bits/stdc++.h>
- #define int long long
- #define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
- using namespace std;
- int a[10][10],s[10];
- int ss=INT_MAX;
- signed main()
- {
- IOS
- int n,m;
- cin>>n>>m;
- for(int i=1;i<=n;i++)
- {
- for(int j=1;j<=m;j++)
- {
- cin>>a[i][j];
- }
- }
- int t=min(n,m);
- s[1]=a[1][1];
- s[2]=a[1][1]*a[2][2]-a[1][2]*a[2][1];
- s[3]=((a[1][1]*a[2][2]*a[3][3]-a[1][3]*a[2][2]*a[3][1])+(a[1][2]*a[2][3]*a[3][1]-a[1][1]*a[2][3]*a[3][2])+(a[1][3]*a[2][1]*a[3][2]-a[1][2]*a[2][1]*a[3][3]));
- //cout<<s[3]<<'\n';
- s[4]=((a[1][1]*a[2][2]*a[3][3]*a[4][4]-a[1][4]*a[2][3]*a[3][2]*a[4][1])+(a[1][2]*a[2][3]*a[3][4]*a[4][1]-a[2][4]*a[3][3]*a[4][2]*a[1][1])+(a[1][3]*a[2][4]*a[3][1]*a[4][2]-a[3][4]*a[4][3]*a[1][2]*a[2][1])+(a[2][1]*a[3][2]*a[4][3]*a[1][4]-a[1][3]*a[2][2]*a[3][1]*a[4][4]));
- s[5]=((a[1][1]*a[2][2]*a[3][3]*a[4][4]*a[5][5]-a[1][5]*a[2][4]*a[3][3]*a[4][2]*a[5][1])+(a[1][2]*a[2][3]*a[3][4]*a[4][5]*a[5][1]-a[2][5]*a[3][4]*a[4][3]*a[5][2]*a[1][1])+(a[1][3]*a[2][4]*a[3][5]*a[4][1]*a[5][2]-a[3][5]*a[4][4]*a[5][3]*a[1][2]*a[2][1])+(a[1][4]*a[2][5]*a[3][1]*a[4][2]*a[5][3]-a[4][5]*a[5][4]*a[1][3]*a[2][2]*a[3][1])+(a[1][5]*a[2][1]*a[3][2]*a[4][3]*a[5][4]-a[5][5]*a[1][4]*a[2][3]*a[3][2]*a[4][1]));
- //int ss=INT_MAX;
- for(int i=1;i<=t;i++)
- {
- //cout<<s[i]<<" ";
- ss=min(s[i],ss);
- }
- if(n==m)
- cout<<ss<<'\n';
- else
- {
- if(ss<=0)
- cout<<ss<<'\n';
- else
- cout<<"0"<<'\n';
- }
- }
复制代码 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |