2023河南萌新联赛第(二)场 南阳理工学院

打印 上一主题 下一主题

主题 928|帖子 928|积分 2784

A. 国际旅行Ⅰ

标题:


思绪:

因为题意上每个国家可以相互到达,以是只需要排序,输出第k小的值就可以了。
AC代码:

  1. #include<bits/stdc++.h>
  2. #define int long long
  3. #define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  4. using namespace std;
  5. int a[1010];
  6. signed main()
  7. {
  8.         IOS
  9.         int n,m,q,u,v,k;
  10.         cin>>n>>m>>q;
  11.         for(int i=0;i<n;i++)
  12.         cin>>a[i];
  13.         for(int i=1;i<=m;i++)
  14.         {
  15.                 cin>>u>>v;
  16.         }
  17.         sort(a,a+n);
  18.         for(int i=1;i<=q;i++)
  19.         {
  20.                 cin>>k;
  21.                 cout<<a[k-1]<<'\n';
  22.         }
  23. }
复制代码
D.A*BBBB

标题:


思绪:

因为数据范围特殊大,假如用高精乘的话会时间超限,但是标题里面说b的每一位数字都是一样的,以是就把该数字题出来,后面都是1*1,只需要用a乘一个个位数,然后再错位相加。
AC代码:

  1. #include<bits/stdc++.h>
  2. #define int long long
  3. #define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  4. using namespace std;
  5. typedef pair<int,int> PII;
  6. const int N=2e6+20;
  7. int a[N],ans[N],num[N],b[N];
  8. signed main()
  9. {
  10.         IOS
  11.         int t;
  12.         cin>>t;
  13.         while(t--)
  14.         {
  15.                 memset(a,0,sizeof(a));
  16.                 string s1,s2;
  17.                 cin>>s1>>s2;
  18.                 reverse(s1.begin(),s1.end());
  19.                 int n=s1.size();
  20.                 for(int i=0;i<n;i++)
  21.                 {
  22.                         b[i]=s1[i]-'0';
  23.                         a[i]+=b[i]*(s2[0]-'0');
  24.                         a[i+1]+=a[i]/10;
  25.                         a[i]%=10;
  26. //                        a[i]*=(s2[0]-'0');
  27. //                        if(a[i]>=10)
  28. //                        {
  29. //                                a[i+1]+=a[i]/10;
  30. //                                a[i]%=10;
  31. //                        }
  32.                 }
  33. //                for(int i=0;i<n;i++)
  34. //                {
  35. //                        if(a[i]>=10)
  36. //                        {
  37. //                                a[i+1]+=a[i]/10;
  38. //                                a[i]%=10;
  39. //                        }
  40. //                }
  41.                 if(a[n]==0) n--;
  42.                 reverse(a,a+n+1);
  43.                 int m=s2.size();
  44.                 ans[0]=a[0];
  45.                 for(int i=1;i<=n;i++)
  46.                 {
  47.                         ans[i]=ans[i-1]+a[i];
  48.                 }
  49.                 int r=-1,l=-m-1;
  50.                 int ss=n+m-1;
  51.                 for(int i=0;i<=ss;i++)
  52.                 {
  53.                         r++;
  54.                         l++;
  55.                         int rr,ll;
  56.                         if(r>n) rr=ans[n];
  57.                         else rr=ans[r];
  58.                         if(l<0) ll=0;
  59.                         else ll=ans[l];
  60.                         num[i]=rr-ll;
  61.                 }
  62.                 for(int i=ss;i>=1;i--)
  63.                 {
  64.                         if(num[i]>=10)
  65.                         {
  66.                                 num[i-1]+=num[i]/10;
  67.                                 num[i]%=10;
  68.                         }
  69.                 }
  70.                 int dd=0;
  71.                 for(int i=0;i<=ss;i++)
  72.                 {
  73.                         if(num[i]==0&&dd==0&&i!=ss) continue;
  74.                         dd=1;
  75.                         cout<<num[i];
  76.                 }
  77.                 cout<<'\n';
  78.         }
  79. }
复制代码
F. 水灵灵的小学弟

标题:


思绪:

一开始一位是个博弈题,刚想开写,发现两个人的字母缩写相同直接输出就可以了。
AC代码:

  1. #include<bits/stdc++.h>
  2. #define int long long
  3. #define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  4. using namespace std;
  5. signed main()
  6. {
  7.         IOS
  8.         int t;
  9.         cin>>t;
  10.         while(t--)
  11.         {
  12.                 int a,b;
  13.                 cin>>a>>b;
  14.                 cout<<"DHY"<<'\n';
  15.         }
  16. }
复制代码
H.狼狼的备忘录

标题:


思绪:

一道模仿题,用了一个map里面套set,假如mp[id]的大小为空的话,就往里面存,否则,遍历这个set,假如mp[id]中有比该字符串长的字符串,就需要判断该字符串是否为厥后缀,遍历完后假如不是mp[id]任何一个的字符串,就存入里面;假如该字符比前面已存入的长,就要遍历这个set,看谁是该字符串的后缀,删掉。最后从头输出map。
AC代码:

  1. #include<bits/stdc++.h>
  2. #define int long long
  3. #define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  4. using namespace std;
  5. signed main()
  6. {
  7.         IOS
  8.        
  9.         int n;
  10.         cin>>n;
  11.         map<string,set<string> > mp;
  12.         for(int i=0;i<n;i++)
  13.         {
  14.                 string id;int op;
  15.                 cin>>id>>op;
  16.                 while(op--)
  17.                 {
  18.                         string x;
  19.                         cin>>x;
  20.                         if(mp[id].empty())
  21.                         mp[id].insert(x);
  22.                         else
  23.                         {
  24.                                 int flag=1;
  25.                                 vector<string> q;
  26.                                 for(auto tt:mp[id])
  27.                                 {
  28.                                         if(tt.size()>=x.size())
  29.                                         {
  30.                                                 int k=tt.rfind(x);
  31.                                                 if(k!=-1)
  32.                                                 {
  33.                                                         if(k+x.size()==tt.size())
  34.                                                         flag=0;
  35.                                                 }
  36.                                                
  37.                                         }
  38.                                         else
  39.                                         {
  40.                                                 int k=x.rfind(tt);
  41.                                                 if(k!=-1)
  42.                                                 {
  43.                                                         if(k+tt.size()==x.size())
  44.                                                         q.push_back(tt);
  45.                                                 }
  46.                                         }
  47.                                 }
  48.                                 if(flag) mp[id].insert(x);
  49.                                 if(!q.empty())
  50.                                 {
  51.                                         for(auto ss:q) mp[id].erase(ss);
  52.                                 }
  53.                         }
  54.                 }
  55.         }
  56.         cout<<mp.size()<<'\n';
  57.         for(auto i:mp)
  58.         {
  59.                 cout<<i.first<<" "<<i.second.size()<<" ";
  60.                 for(auto j:i.second)
  61.                 cout<<j<<" ";
  62.                 cout<<'\n';
  63.         }
  64.        
  65. }
复制代码
I.重生之zbk要拿回属于他的统统

标题:


思绪:

暴力遍历一遍就可以了。
AC代码:

  1. #include<bits/stdc++.h>
  2. #define int long long
  3. #define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  4. using namespace std;
  5. signed main()
  6. {
  7.         IOS
  8.         int n,t=0;
  9.         cin>>n;
  10.         string s;
  11.         cin>>s;
  12.         for(int i=0;i<n;i++)
  13.         {
  14.                 //cout<<s[i]<<" ";
  15.                 if(s[i]=='c')
  16.                 {
  17.                         if(s[i+1]=='h'&&s[i+2]=='u'&&s[i+3]=='a'&&s[i+4]=='n')
  18.                         {
  19.                                 t++;
  20.                                 s[i]='s';
  21.                                 s[i+1]='s';
  22.                                 s[i+2]='s';
  23.                                 s[i+3]='s';
  24.                                 s[i+4]='s';
  25.                         }
  26.                 }
  27.         }
  28.         cout<<t<<'\n';
  29. }
复制代码
J. 这是签到

标题:


思绪:

数据范围特殊小,我直接纯暴力写的,根据下面给的33的公式,推出来4,5的,直接暴力给a了。

根据3
3的行列式可以得出,最闭幕果是主对角线对应的乘积减去副对角线对应的乘积的和。好比从左上出发最长的正对角线对应的是从右上出发最长的正对角线相减;左上的正对角线右边的一个对角线加上左下对应右上的正对角线右边的一个对角线加上左上,依次类推,可以得出4,5的公式。
AC代码:

  1. #include<bits/stdc++.h>
  2. #define int long long
  3. #define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  4. using namespace std;
  5. int a[10][10],s[10];
  6. int ss=INT_MAX;
  7. signed main()
  8. {
  9.         IOS
  10.         int n,m;
  11.         cin>>n>>m;
  12.         for(int i=1;i<=n;i++)
  13.         {
  14.                 for(int j=1;j<=m;j++)
  15.                 {
  16.                         cin>>a[i][j];
  17.                 }
  18.         }
  19.         int t=min(n,m);
  20.         s[1]=a[1][1];
  21.         s[2]=a[1][1]*a[2][2]-a[1][2]*a[2][1];
  22.         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]));
  23.         //cout<<s[3]<<'\n';
  24.         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]));
  25.         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]));
  26.         //int ss=INT_MAX;
  27.         for(int i=1;i<=t;i++)
  28.         {
  29.                 //cout<<s[i]<<" ";
  30.                 ss=min(s[i],ss);
  31.         }
  32.         if(n==m)
  33.         cout<<ss<<'\n';
  34.         else
  35.         {
  36.                 if(ss<=0)
  37.                 cout<<ss<<'\n';
  38.                 else
  39.                 cout<<"0"<<'\n';
  40.         }
  41. }
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

小小小幸运

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表