title: ACM-CodeForces-#685(Div.2)
tags:

  • ACM
  • CF
    abbrlink: e1e96252
    date: 2020-11-22 10:46:08

好久没见过CF有这么水的contest了,蒟蒻赶紧找找自信

A. Subtract or Divide

  1. #include<iostream>
  2. using namespace std;
  3. int main(){
  4. int T,n;
  5. cin>>T;
  6. while(T--)
  7. {
  8. cin>>n;
  9. if(n<=3) n--;
  10. else n=2+(n&1);
  11. cout<<n<<endl;
  12. }
  13. return 0;
  14. }

B. Non-Substring Subsequence

  1. #include<iostream>
  2. #include<cstring>
  3. using namespace std;
  4. int main(){
  5. int T;
  6. cin>>T;
  7. while(T--)
  8. {
  9. int n,q;
  10. string s;
  11. cin>>n>>q>>s;
  12. while(q--)
  13. {
  14. int l,r;
  15. bool good=false;
  16. cin>>l>>r;
  17. l--;
  18. r--;
  19. for(int i=0;i<l && good==false; i++)
  20. if(s[i]==s[l]) good=true;
  21. for(int i=r+1;i<n && good==false;i++)
  22. if(s[i]==s[r]) good=true;
  23. if(good==true) cout<<"YES"<<endl;
  24. else cout<<"NO"<<endl;
  25. }
  26. }
  27. return 0;
  28. }

C. String Equality

这里有必要记录两个很有意思的小知识点,都是C11标准里面新增的,array数组和auto类型变量,auto类型可以根据你赋值的数据自动分配数据类型,用起来十分方便

array 模板定义了一种相当于标准数组的容器类型。它是一个有 N 个 T 类型元素的固定序列。除了需要指定元素的类型和个数之外,它和常规数组没有太大的差别。显然,不能增加或删除元素。

模板实例的元素被内部存储在标准数组中。和标准数组相比,array 容器的额外幵销很小,但提供了两个优点:如果使用 at(),当用一个非法的索引访问数组元素时,能够被检测到,因为容器知道它有多少个元素,这也就意味着数组容器可以作为参数传给函数,而不再需要单独去指定数组元素的个数。

使用 array 容器类型时,需要在源文件中包含头文件 array。

  1. #include<iostream>
  2. #include<cstring>
  3. #include<algorithm>
  4. #include<array>
  5. using namespace std;
  6. int main(){
  7. int T;
  8. cin>>T;
  9. while(T--)
  10. {
  11. int n,k;
  12. string s1,s2;
  13. array<int, 27> have{}, need{};
  14. cin>>n>>k>>s1>>s2;
  15. for(auto& c: s1)
  16. have[c-'a']++;
  17. for(auto& c: s2)
  18. need[c-'a']++;
  19. bool good = true;
  20. for(int i=0;i<26;i++)
  21. {
  22. if(have[i]<need[i] || (have[i] -= need[i]) % k)
  23. good=false;
  24. have[i+1]+=have[i];
  25. }
  26. if(good) cout<<"Yes"<<endl;
  27. else cout<<"No"<<endl;
  28. }
  29. return 0;
  30. }

D.Circle Game

逻辑题

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int T;
  6. cin >> T;
  7. while(T--) {
  8. int n, k;
  9. cin >> n >> k;
  10. int x = 0, y = 0;
  11. for(;;)
  12. {
  13. if(x <= y && pow(x+k, 2) + pow(y, 2) <= pow(n, 2))
  14. x += k;
  15. else if(x > y && pow(y+k, 2) + pow(x, 2) <= pow(n,2))
  16. y += k;
  17. else break;
  18. }
  19. if(x == y)
  20. cout << "Utkarsh" << endl;
  21. else
  22. cout << "Ashish" << endl;
  23. }
  24. return 0;
  25. }