AtCoder Beginner Contest 371

[复制链接]
发表于 2026-1-21 08:51:27 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

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

×
A - Jiro :

标题:


代码:
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL ;
  4. typedef pair<int,int> PII;
  5. void solve()
  6. {
  7.     string a,b, c;
  8.     cin>>a>>b>>c;
  9.     string s(3,'a');
  10.     s[0]=a[0];
  11.     s[1]=b[0];
  12.     s[2]=c[0];
  13.    
  14.     // a b c
  15.     // c b a
  16.     // b a c
  17.     // c a b
  18.     // a c b
  19.     // b c a
  20.     if(s[0]=='>' && s[1]=='>' && s[2]=='>') cout<<'B';
  21.     else if(s[0]=='<' && s[1]=='<' && s[2]=='<') cout<<'B';
  22.     else if(s[0]=='<' && s[1]=='>' && s[2]=='>') cout<<'A';
  23.     else if(s[0]=='>' && s[1]=='<' && s[2]=='<') cout<<'A';
  24.     else cout<<'C';
  25. }
  26. int main()
  27. {
  28.     int T;
  29.     // cin>>T;
  30.     T=1;
  31.     while(T--){
  32.         solve();
  33.     }
  34.     return 0;
  35. }
复制代码
B - Taro

标题:

代码:
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL ;
  4. typedef pair<int,int> PII;
  5. void solve()
  6. {
  7.         int n,m;
  8.         cin>>n>>m;
  9.         vector<int> a(m);
  10.         string b(m,' ');
  11.         vector<int> h(n);
  12.         for(int i=0; i<m; i++){
  13.                 cin>>a[i]>>b[i];
  14.                 a[i]--;
  15.                 if(b[i]=='M'){
  16.                         h[a[i]]++;
  17.                 }
  18.                 if(h[a[i]]==1 &&b[i]=='M') cout<<"Yes\n";
  19.                 else cout<<"No\n";
  20.         }
  21. }
  22. int main()
  23. {
  24.     int T;
  25.     // cin>>T;
  26.     T=1;
  27.     while(T--){
  28.         solve();
  29.     }
  30.     return 0;
  31. }
复制代码
C - Make Isomorphic:

标题:



思绪:

找到g i 与 h j 顶点的对应关系,摆列(1,..,n) 的全分列,盘算每种分列对应的耗费,取最小值.
代码:
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4. typedef pair<int,int> PII;
  5. void solve()
  6. {
  7.         int n;
  8.         cin>>n;
  9.         vector w(n,vector(n,0)),g(n,vector(n,0)), h(n,vector(n,0));
  10.        
  11.         int mg;
  12.         cin>>mg;
  13.         for(int i=0;i <mg; i++){
  14.                 int a, b;
  15.                 cin>>a>>b;
  16.                 a--, b--;
  17.                 g[a][b]=1;
  18.                 g[b][a]=1;
  19.         }
  20.         int mh;
  21.         cin>>mh;
  22.         for(int i=0; i<mh; i++){
  23.                 int a,b;
  24.                 cin>>a>>b;
  25.                 a--, b--;
  26.                 h[a][b]=1;
  27.                 h[b][a]=1;
  28.         }
  29.         for(int i=0; i<n; i++){
  30.                 for(int j=i+1; j<n; j++){
  31.                         cin>>w[i][j];
  32.                 }
  33.         }
  34.         vector<int> p(n);
  35.         iota(p.begin(),p.end(),0);
  36.         int ans=1e9;
  37.         do{
  38.                 int res=0;
  39.                 for(int i=0;i<n; i++){
  40.                         for(int j=i+1; j<n; j++){
  41.                                 if(h[i][j]!=g[p[i]][p[j]]){
  42.                                         res+=w[i][j];
  43.                                 }
  44.                         }
  45.                 }
  46.                 ans=min(ans,res);
  47.         }while(next_permutation(p.begin(),p.end()));
  48.        
  49.         cout<<ans<<"\n";
  50.        
  51. }
  52. int main()
  53. {
  54.         int T;
  55. //        cin>>T;
  56.         T=1;
  57.         while(T--){
  58.                 solve();
  59.         }
  60.         return 0;
  61. }
复制代码
D - 1D Country:

标题:


思绪:

离散化+二分查找
代码:
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4. int main()
  5. {
  6.     int n;
  7.     cin>>n;
  8.     vector<int> x(n+1), p(n+1);
  9.     x[0]=-0x3f3f3f3f;
  10.     for(int i=1; i<=n; i++) cin>>x[i];
  11.     for(int i=1; i<=n; i++) cin>>p[i];
  12.     vector<LL> s(n+1);
  13.     for(int i=1; i<=n; i++){
  14.         s[i]=s[i-1]+p[i];
  15.     }
  16.     int q;
  17.     cin>>q;
  18.     while(q--){
  19.         int a,b;
  20.         cin>>a>>b;
  21.         int l=lower_bound(x.begin(), x.end(), a)-x.begin();
  22.         int r=upper_bound(x.begin(), x.end(), b)-x.begin()-1;
  23.         cout<<s[r]-s[l-1]<<'\n';
  24.     }
  25.    
  26.     return 0;
  27. }
复制代码
E - I Hate Sigma Problems 

标题:


思绪:

求每个Ai的贡献,

代码:
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4. int main()
  5. {
  6.     int n;
  7.     cin>>n;
  8.     vector<int> a(n+1);
  9.     vector<vector<int>> pos(n+1);
  10.     for(int  i=1; i<=n; i++){
  11.         cin>>a[i];
  12.         pos[a[i]].push_back(i);
  13.     }
  14.     LL ans=0;
  15.     for(int i=1; i<=n; i++){
  16.         int ls=0;
  17.         for(auto j: pos[i]) ans+=1LL*(j-ls)*(n-j+1), ls=j;
  18.     }
  19.     cout<<ans<<'\n';
  20. }
复制代码
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表