Codeforces Round #719 (Div. 3)(a,b,c)

「爱情、让人受尽委屈。」 2023-01-19 07:29 156阅读 0赞

题目https://codeforc.es/contest/1520

简单题

  • a
  • b
  • c

a

一个字符串,出现在一个地方的字符,不能再第二个地方出现

A A A A Z A A A A A AAAAZAAAAA AAAAZAAAAA -———NO
F F G Z Z Z Y FFGZZZY FFGZZZY -—————— YES

  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4. const int N = 1e4;
  5. int u[N+10], s[N+10];
  6. void solve()
  7. {
  8. int n; cin >> n;
  9. string str; cin >> str;
  10. if (n == 1) puts("YES"),return;
  11. char ch;
  12. for (int i = 0; i < n; i++)
  13. {
  14. if (str[i] != str[i+1])
  15. {
  16. ch = str[i]; // find the first different index
  17. for (int j = i+1; j < n; j++)
  18. {
  19. if (str[i] == str[j]) puts("NO"), return;
  20. }
  21. }
  22. }
  23. puts("YES");
  24. }
  25. int main()
  26. {
  27. ios_base::sync_with_stdio(false);
  28. cin.tie(nullptr); cout.tie(nullptr);
  29. int T; cin >> T;
  30. while (T--)
  31. solve();
  32. return 0;
  33. }

b

1到n共有多少位数都相同的数

位数相同的数 1 2 3…9, 11, 22…111…11111…

暴力,肯定是不行的
虽然是div3,否则还不如给大家布置c++课后作业?

  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4. ll fun (int a, int b)
  5. {
  6. ll ans = 0;
  7. int cnt = 1;
  8. for (int i = 1; i <= a; ++i){
  9. ans += cnt * b;
  10. cnt *= 10;
  11. }
  12. return ans;
  13. }
  14. void solve()
  15. {
  16. ll n, ans = 0; cin >> n;
  17. for (int i = 1; i <= 9; ++i)
  18. for (int j = 1; j <= 9; ++j)
  19. if (fun(i , j) <= n) ans++;
  20. cout << ans << endl;
  21. }
  22. int main()
  23. {
  24. ios_base::sync_with_stdio(false);
  25. cin.tie(nullptr); cout.tie(nullptr);
  26. int T; cin >> T;
  27. while (T--)
  28. solve();
  29. return 0;
  30. }

或者可以打表

  1. int paiduan(int n)
  2. {
  3. int count=0;
  4. if(n<10)return n;
  5. else if(n<=100)
  6. {
  7. n=n/11;
  8. return 9+n;
  9. }
  10. else if(n<=1000)
  11. {
  12. n=n/111;
  13. return 18+n;
  14. }
  15. else if(n<=10000)
  16. {
  17. n=n/1111;
  18. return 27+n;
  19. }
  20. else if(n<=100000)
  21. {
  22. n=n/11111;
  23. return 36+n;
  24. }
  25. else if(n<=1000000)
  26. {
  27. n=n/111111;
  28. return 45+n;
  29. }
  30. else if(n<=10000000)
  31. {
  32. n=n/1111111;
  33. return 54+n;
  34. }
  35. else if(n<=100000000)
  36. {
  37. n=n/11111111;
  38. return 63+n;
  39. }
  40. else
  41. {
  42. n=n/111111111;
  43. return 72+n;
  44. }
  45. }

c

输入一个数n
上下左右四个值相差大于1

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. void solve()
  4. {
  5. int n; cin >> n;
  6. if (n == 2) {
  7. cout << "-1\n";
  8. } else {
  9. for (int i = 1; i <= n * n; i += 2) {
  10. cout << i << ' ';
  11. if ((i + 1) % n == 0) cout << endl;
  12. }
  13. for (int i = 2; i <= n * n; i += 2) {
  14. cout << i << ' ';
  15. if ((i + 1) % n == 0) cout << endl;
  16. }
  17. }
  18. }
  19. int main()
  20. {
  21. ios_base::sync_with_stdio(false);
  22. cin.tie(nullptr); cout.tie(nullptr);
  23. int T; cin >> T;
  24. while (T--)
  25. solve();
  26. return 0;
  27. }

发表评论

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

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

相关阅读