Codeforces Round #573 (Div. 2)

浅浅的花香味﹌ 2021-09-29 13:10 407阅读 0赞























Sloved A B C D E F
6/6 O O O O Ø Ø
  • O for passing during the contest
  • Ø for passing after the contest
  • ! for attempted but failed
  • · for having not attempted yet

A.Tokitsukaze and Enhancement(0:05,+1)

签到题,读题找规律即可

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define rep(i,a,n) for (int i=a;i<n;i++)
  4. #define per(i,a,n) for (int i=n-1;i>=a;i--)
  5. #define pb push_back
  6. #define mp make_pair
  7. #define all(x) (x).begin(),(x).end()
  8. #define fi first
  9. #define se second
  10. #define SZ(x) ((int)(x).size())
  11. typedef vector<int> VI;
  12. typedef long long ll;
  13. typedef pair<int,int> PII;
  14. const ll mod=1000000007;
  15. ll powmod(ll a,ll b) { ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){ if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
  16. ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
  17. int n;
  18. int main(int argc, char const *argv[])
  19. {
  20. ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  21. cin >> n;
  22. int x = n % 4;
  23. if(x == 1)
  24. {
  25. cout << 0 << " " << "A"<< endl;
  26. }
  27. if(x == 2)
  28. {
  29. cout << 1 << " " << "B"<< endl;
  30. }
  31. if(x == 3)
  32. {
  33. cout << 2 << " " << "A"<< endl;
  34. }
  35. if(x == 0)
  36. {
  37. cout << 1 << " " << "A"<< endl;
  38. }
  39. return 0;
  40. }

B.Tokitsukaze and Mahjong(0:24,+3)

模拟,注意1m 3m 5m的情况

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define rep(i,a,n) for (int i=a;i<n;i++)
  4. #define per(i,a,n) for (int i=n-1;i>=a;i--)
  5. #define pb push_back
  6. #define mp make_pair
  7. #define all(x) (x).begin(),(x).end()
  8. #define fi first
  9. #define se second
  10. #define SZ(x) ((int)(x).size())
  11. typedef vector<int> VI;
  12. typedef long long ll;
  13. typedef pair<int,int> PII;
  14. const ll mod=1000000007;
  15. ll powmod(ll a,ll b) { ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){ if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
  16. ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
  17. string str[10];
  18. int cnt[5][10];
  19. int main(int argc, char const *argv[])
  20. {
  21. ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  22. rep(i,0,3)
  23. {
  24. cin >> str[i];
  25. if(str[i][1] == 's')
  26. {
  27. cnt[0][str[i][0]-'0']++;
  28. }
  29. else if(str[i][1] == 'p')
  30. {
  31. cnt[1][str[i][0]-'0']++;
  32. }
  33. else
  34. {
  35. cnt[2][str[i][0]-'0']++;
  36. }
  37. }
  38. int ans = 2;
  39. //
  40. rep(i,0,3)
  41. {
  42. rep(j,1,10)
  43. {
  44. if(cnt[i][j])
  45. {
  46. ans = min(ans,3-cnt[i][j]);
  47. }
  48. }
  49. }
  50. int s = 0;
  51. rep(i,0,3)
  52. {
  53. s = 0;
  54. rep(j,1,10)
  55. {
  56. if(cnt[i][j])
  57. {
  58. s+=1;
  59. }
  60. else
  61. {
  62. ans = min(ans,3-s);
  63. s = 0;
  64. }
  65. }
  66. ans = min(ans,3-s);
  67. }
  68. rep(i,0,3)
  69. {
  70. rep(j,1,8)
  71. {
  72. if(cnt[i][j] && cnt[i][j+2])
  73. {
  74. ans = min(ans,1);
  75. }
  76. }
  77. }
  78. cout << ans << endl;
  79. return 0;
  80. }

C.Tokitsukaze and Discard Items(00:48,+1)

直接O(n)遍历模拟即可,不要想复杂

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define rep(i,a,n) for (int i=a;i<n;i++)
  4. #define per(i,a,n) for (int i=n-1;i>=a;i--)
  5. #define pb push_back
  6. #define mp make_pair
  7. #define all(x) (x).begin(),(x).end()
  8. #define fi first
  9. #define se second
  10. #define SZ(x) ((int)(x).size())
  11. typedef vector<int> VI;
  12. typedef long long ll;
  13. typedef pair<int,int> PII;
  14. const ll mod=1000000007;
  15. ll powmod(ll a,ll b) { ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){ if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
  16. ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
  17. const int maxn = 1e5+100;
  18. ll n,m,k;
  19. ll p;
  20. int main(int argc, char const *argv[])
  21. {
  22. ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  23. cin >> n >> m >> k;
  24. ll ans = 0;
  25. ll t = 0;//dz
  26. ll s = 0;//-
  27. ll s1 = 0;
  28. rep(i,0,m)
  29. {
  30. cin >> p;
  31. p -= s;
  32. if((p%k == 0 && p / k == t)||(p%k != 0 && p / k + 1 == t))
  33. {
  34. s1++;
  35. }
  36. else
  37. {
  38. p -= s1 - s;
  39. s = s1;
  40. ans++;
  41. //cout << i << "----" << endl;
  42. if(p % k == 0)
  43. {
  44. t = p / k;
  45. }
  46. else
  47. t = p / k + 1;
  48. s1++;
  49. }
  50. }
  51. cout << ans << endl;
  52. return 0;
  53. }

D.Tokitsukaze, CSL and Stone Game(01:35,+2)

考虑几种情况

  • 2 2 3和1 2 2,后一种cslnb
  • 计算数的个数大于2的总数,cnt >= 2,则cslnb(包括 3 3 3这种情况)
  • 一些显然得到答案的方案

最后特判完,假如还没有得到结果,则最后的局面应为 0 1 2 3 … n-1,直接作差,%2判断即可

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define rep(i,a,n) for (int i=a;i<n;i++)
  4. #define per(i,a,n) for (int i=n-1;i>=a;i--)
  5. #define pb push_back
  6. #define mp make_pair
  7. #define all(x) (x).begin(),(x).end()
  8. #define fi first
  9. #define se second
  10. #define SZ(x) ((int)(x).size())
  11. typedef vector<int> VI;
  12. typedef long long ll;
  13. typedef pair<int,int> PII;
  14. const ll mod=1000000007;
  15. ll powmod(ll a,ll b) { ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){ if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
  16. ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
  17. const int maxn = 1e5 + 1000;
  18. ll n;
  19. ll a[maxn];
  20. int main(int argc, char const *argv[])
  21. {
  22. ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  23. cin >> n;
  24. ll sum = 0;
  25. int zero = 0;
  26. rep(i,0,n)
  27. {
  28. cin >> a[i];
  29. if(a[i] == 0)
  30. {
  31. zero++;
  32. }
  33. sum += a[i];
  34. }
  35. if(sum == 0)
  36. {
  37. cout << "cslnb" << endl;
  38. return 0;
  39. }
  40. if(zero >= 2)
  41. {
  42. cout << "cslnb" << endl;
  43. return 0;
  44. }
  45. if(n == 1) // judge only
  46. {
  47. if(sum % 2 == 0)
  48. {
  49. cout << "cslnb"<<endl;
  50. }
  51. else
  52. {
  53. cout << "sjfnb"<<endl;
  54. }
  55. return 0;
  56. }
  57. sort(a,a+n);
  58. int cnt = 0;
  59. int t = 0;
  60. int wz = 0;
  61. rep(i,0,n)
  62. {
  63. if(a[i] == a[i+1])
  64. {
  65. cnt++;
  66. t = a[i];
  67. wz = i;
  68. }
  69. }
  70. if(cnt >= 2)
  71. {
  72. cout <<"cslnb" << endl;
  73. return 0;
  74. }
  75. else if(cnt == 1)
  76. {
  77. if(wz == 0 || a[wz-1] < t-1)
  78. {
  79. sum -= (0+n-1)*n/2;
  80. if(sum % 2 == 0)
  81. {
  82. cout << "cslnb"<<endl;
  83. }
  84. else
  85. {
  86. cout << "sjfnb"<<endl;
  87. }
  88. return 0;
  89. }
  90. else
  91. {
  92. cout << "cslnb" << endl;
  93. return 0;
  94. }
  95. }
  96. else
  97. {
  98. sum -= (0+n-1)*n/2;
  99. if(sum % 2 == 0)
  100. {
  101. cout << "cslnb"<<endl;
  102. }
  103. else
  104. {
  105. cout << "sjfnb"<<endl;
  106. }
  107. }
  108. return 0;

E.Tokitsukaze and Duel

找出第一个和最后一个1,第一个和最后一个0
sjf胜利的条件很简单,zero2 - zero1 < k || one2- one1 < k
难点在qls的回合判断
现在设计一个数组a,元素为zero2 , zero1 , one2, one1,并排序

  • 已知在qls的回合,qls不可能输,顶多once again

qls胜利,条件为a2-a0 <= k and a3-a1 <= k

  • 已经判断了第一回合,则a1和a2不可能同是0或1,即a0和a3为0和1
  • 无论sjf选择哪一段,必包括a1和a2
  • 假设sjf把那一段变成1,qls可以把边缘的0到中间一段变成1,同理假设sjf把那一段变成0,qls可以把边缘的1到中间一段变成0
  • 重点在于无论如何,当满足条件时,sjf无论如何操作都覆盖到了中间的0和1

假设不满足这个条件,则sjf必定可以选择一段不覆盖中间的0和1,qls只能选择once again
具体要理解清楚可能需要自己举一些例子,或者严格证明一下

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define rep(i,a,n) for (int i=a;i<n;i++)
  4. #define per(i,a,n) for (int i=n-1;i>=a;i--)
  5. #define pb push_back
  6. #define mp make_pair
  7. #define all(x) (x).begin(),(x).end()
  8. #define fi first
  9. #define se second
  10. #define SZ(x) ((int)(x).size())
  11. typedef vector<int> VI;
  12. typedef long long ll;
  13. typedef pair<int,int> PII;
  14. const ll mod=1000000007;
  15. ll powmod(ll a,ll b) { ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){ if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
  16. ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
  17. int n,k;
  18. string str;
  19. int one1,one2;
  20. int zero1,zero2;
  21. int a[10];
  22. int main(int argc, char const *argv[])
  23. {
  24. cin >> n >> k;
  25. cin >> str;
  26. rep(i,0,n)
  27. {
  28. if(str[i] == '0')
  29. {
  30. if(zero1 == 0)
  31. {
  32. zero1 = i + 1;
  33. }
  34. zero2 = i + 1;
  35. }
  36. if(str[i] == '1')
  37. {
  38. if(one1 == 0)
  39. {
  40. one1 = i + 1;
  41. }
  42. one2 = i + 1;
  43. }
  44. }
  45. if(zero2 - zero1 < k || one2 - one1 < k)
  46. {
  47. cout << "tokitsukaze" << endl;
  48. return 0;
  49. }
  50. a[0] = zero1;
  51. a[1] = zero2;
  52. a[2] = one1;
  53. a[3] = one2;
  54. sort(a,a+4);
  55. if(a[3] - a[1] <= k && a[2] - a[0] <= k)
  56. {
  57. cout << "quailty" << endl;
  58. return 0;
  59. }
  60. cout << "once again" << endl;
  61. return 0;
  62. }

F.Tokitsukaze and Strange Rectangle

扫描线+离散化

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define rep(i,a,n) for (int i=a;i<n;i++)
  4. #define per(i,a,n) for (int i=n-1;i>=a;i--)
  5. #define pb push_back
  6. #define mp make_pair
  7. #define all(x) (x).begin(),(x).end()
  8. #define fi first
  9. #define se second
  10. #define SZ(x) ((int)(x).size())
  11. typedef vector<int> VI;
  12. typedef long long ll;
  13. typedef pair<int,int> PII;
  14. const ll mod=1000000007;
  15. ll powmod(ll a,ll b) { ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){ if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
  16. ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
  17. //树状数组
  18. struct Bit
  19. {
  20. vector<int> a;
  21. int sz;
  22. void init(int n)
  23. {
  24. sz=n+5;
  25. for(int i=1;i<=n+5;i++)
  26. a.push_back(0);
  27. }
  28. int lowbit(int x)
  29. {
  30. return x&(-x);
  31. }
  32. int query(int x)
  33. {
  34. int ans = 0;
  35. for(;x;x-=lowbit(x))ans+=a[x];
  36. return ans;
  37. }
  38. int query(int l ,int r)
  39. {
  40. return query(r) - query(l-1);
  41. }
  42. void update(int x,int v)
  43. {
  44. for(;x<sz;x+=lowbit(x))
  45. a[x]+=v;
  46. }
  47. }bit;
  48. const int maxn = 2e5 + 100;
  49. VI x[maxn],y; // lsy x, unique y
  50. map<int,int> lsx,lsy,cntx;// id of discrete x,y , number of x
  51. int n;
  52. int main(int argc, char const *argv[])
  53. {
  54. ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  55. cin >> n;
  56. bit.init(n);
  57. int sum = 0;
  58. rep(i,0,n)
  59. {
  60. int xx,yy;
  61. cin >> xx >> yy;
  62. if(!lsy.count(yy))
  63. {
  64. lsy[yy] = sum++;
  65. y.pb(yy);
  66. }
  67. x[lsy[yy]].pb(xx);
  68. cntx[xx]++;
  69. }
  70. sort(all(y));
  71. // for(auto v : y)
  72. // {
  73. // sort(all(x[lsy[v]]));
  74. // }
  75. int s = 0;
  76. for(auto v:cntx)
  77. {
  78. s++;
  79. lsx[v.fi] = s;
  80. bit.update(s,1);
  81. }
  82. ll ans = 0;
  83. for(auto v : y)
  84. {
  85. sort(all(x[lsy[v]]));
  86. int pre = 1;
  87. for(auto u : x[lsy[v]])
  88. {
  89. ans += 1ll * bit.query(pre,lsx[u]) * bit.query(lsx[u],s);
  90. //cout << pre << " "<< lsx[u] <<" " << bit.query(pre,lsx[u]) << "---" << endl;
  91. //cout << s << " " << bit.query(lsx[u],s) << endl;
  92. pre = lsx[u] + 1;
  93. cntx[u]--;
  94. if(cntx[u] == 0)
  95. {
  96. //cntx.erase(u);
  97. bit.update(lsx[u],-1);
  98. }
  99. }
  100. }
  101. cout << ans << endl;
  102. return 0;
  103. }

发表评论

表情:
评论列表 (有 0 条评论,407人围观)

还没有评论,来说两句吧...

相关阅读

    相关 codeforces-round375-div2

    题目链接:[codeforces round 375 div2][] A题: 读一遍题目就知道是超级水的题目,,就是给你三个坐标,求三个坐标汇集到一个点所走的路程