CF1178团队刷题目日记

A

Prime Minister

Problem - A - Codeforces

  1. #include<vector>
  2. #include<iostream>
  3. using namespace std;
  4. int main(){
  5. int n;
  6. cin>>n;
  7. vector<int>a(n);
  8. vector<int>b(n,0);
  9. int sum=0;
  10. int sum1=0;
  11. int cnt=1;
  12. for(int i=0;i<n;i++)
  13. {
  14. cin >> a[i];
  15. sum+=a[i];
  16. if(a[i]<a[0]/2+1)
  17. {
  18. b[i]=1;
  19. cnt++;
  20. sum1+=a[i];
  21. }
  22. }
  23. b[0]=1;
  24. sum1+=a[0];
  25. if(2*sum1<=sum)
  26. cout<<"0"<<endl;
  27. else
  28. {
  29. cout<<cnt<<endl;
  30. for(int i=0;i<n;i++)
  31. {
  32. if(b[i]==1)
  33. cout<<i+1<<" ";
  34. }
  35. }
  36. return 0;
  37. }
B

WOW Factor

Problem - B - Codeforces

  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. using namespace std;
  5. using LL = long long;
  6. int main()
  7. {
  8. LL result = 0;
  9. string s;
  10. cin >> s;
  11. vector<LL> prefix_vn(s.length());
  12. vector<LL> suffix_vn(s.length());
  13. for (LL i = 0; i < s.length() - 1; ++i)
  14. {
  15. if (s[i] == 'v' && i > 0 && s[i - 1] == 'v')
  16. prefix_vn[i + 1] = 1;
  17. prefix_vn[i + 1] += prefix_vn[i];
  18. }
  19. for (LL i = 0; i < s.length() - 1; ++i)
  20. {
  21. if (s[s.length() - i - 1] == 'v' && i > 0 && s[s.length() - i] == 'v')
  22. suffix_vn[s.length() - i - 2] = 1;
  23. suffix_vn[s.length() - i - 2] += suffix_vn[s.length() - i - 1];
  24. }
  25. for (LL i = 0; i < s.length(); ++i)
  26. if (s[i] == 'o')
  27. result += prefix_vn[i] * suffix_vn[i];
  28. cout << result << '\n';
  29. return 0;
  30. }
C

Tiles

Problem - C - Codeforces

  1. #include <iostream>
  2. using namespace std;
  3. using LL = long long;
  4. const LL MODULO = 998'244'353;
  5. LL fast_pow(LL base, LL exp)
  6. {
  7. LL result = 0, mult = 0;
  8. result = 1;
  9. mult = base;
  10. while (exp > 0)
  11. {
  12. if (exp % 2 == 1)
  13. result = result * mult % MODULO;
  14. mult = mult * mult % MODULO;
  15. exp /= 2;
  16. }
  17. return result;
  18. }
  19. int main()
  20. {
  21. LL width = 0, height = 0;
  22. cin >> width >> height;
  23. cout << fast_pow(2, width + height) << '\n';
  24. return 0;
  25. }
D

Prime Graph

Problem - D - Codeforces

  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. bool is_prime(int n)
  5. {
  6. if (n <= 1)
  7. return false;
  8. for (int f = 2; f * f <= n; ++f)
  9. if (n % f == 0)
  10. return false;
  11. return true;
  12. }
  13. const int N = 1'000;
  14. int degrees[N];
  15. int main()
  16. {
  17. int n = 0, extra = 0;
  18. cin >> n;
  19. vector<pair<int, int>> edges;
  20. for (int i = 0; i < n; ++i)
  21. edges.push_back({i, (i + 1) % n});
  22. while (!is_prime(n + extra))
  23. ++extra;
  24. for (int i = 0; i < extra; ++i)
  25. edges.push_back({i, (i + n / 2) % n});
  26. cout << n + extra << '\n';
  27. for (int i = 0; i < n + extra; ++i)
  28. cout << edges[i].first + 1 << ' ' << edges[i].second + 1 << '\n';
  29. return 0;
  30. }
E

Archaeology

Problem - E - Codeforces

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. string s;
  4. char cur;
  5. int l,r;
  6. void solve()
  7. {
  8. cin>>s;
  9. deque<int>a,b,c;
  10. for(int i=0;i<s.size();i++)
  11. {
  12. if(s[i]=='a')a.push_back(i);
  13. else if(s[i]=='b')b.push_back(i);
  14. else c.push_back(i);
  15. if(s.size()%2==1&&i==s.size()/2)cur=s[i];
  16. }
  17. string ans="";
  18. if(a.size()>=s.size()/2)
  19. {
  20. for(int i=1;i<=s.size()/2;i++)cout<<'a';
  21. puts("");
  22. return;
  23. }
  24. if(b.size()>=s.size()/2)
  25. {
  26. for(int i=1;i<=s.size()/2;i++)cout<<'b';
  27. puts("");
  28. return;
  29. }
  30. if(c.size()>=s.size()/2)
  31. {
  32. for(int i=1;i<=s.size()/2;i++)cout<<'c';
  33. puts("");
  34. return;
  35. }
  36. int maxx;
  37. while(1)
  38. {
  39. maxx=max(max(a.back()-a.front(),b.back()-b.front()),c.back()-c.front());
  40. if(maxx==a.back()-a.front())
  41. {
  42. l=a.front(),r=a.back();
  43. ans+='a';
  44. }
  45. else if(maxx==b.back()-b.front())
  46. {
  47. l=b.front(),r=b.back();
  48. ans+='b';
  49. }
  50. else
  51. {
  52. l=c.front(),r=c.back();
  53. ans+='c';
  54. }
  55. while(!a.empty()&&a.front()<=l)a.pop_front();
  56. while(!b.empty()&&b.front()<=l)b.pop_front();
  57. while(!c.empty()&&c.front()<=l)c.pop_front();
  58. while(!a.empty()&&a.back()>=r)a.pop_back();
  59. while(!b.empty()&&b.back()>=r)b.pop_back();
  60. while(!c.empty()&&c.back()>=r)c.pop_back();
  61. if(a.size()<=1&&b.size()<=1&&c.size()<=1)break;
  62. }
  63. //reverse(ans.begin(),ans.end());
  64. if(ans.size()*2+(a.size()>=1||b.size()>=1||c.size()>=1)<s.size()/2)
  65. {
  66. puts("IMPOSSIBLE");
  67. return;
  68. }
  69. cout<<ans;
  70. if(a.size()>=1)cout<<'a';
  71. else if(b.size()>=1)cout<<'b';
  72. else if(c.size()>=1)cout<<'c';
  73. reverse(ans.begin(),ans.end());
  74. cout<<ans;
  75. puts("");
  76. }
  77. int main()
  78. {
  79. int t=1;
  80. //cin>>t;
  81. while(t--)solve();
  82. }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值