A

如果\(n = m\),答案为\(2 \times n\);如果\(n \ne m\),答案为\(2 \times max(n,m) - 1\)


  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int n, m;
  4. int main()
  5. {
  6. int __;
  7. scanf("%d", &__);
  8. while(__ -- )
  9. {
  10. scanf("%d%d", &n, &m);
  11. printf("%d\n", 2 * max(n, m) - (m != n));
  12. }
  13. return 0;
  14. }

B

\(max(a_i) \times (n - 1) <= sum + ans\) , 并且\((n - 1) \mid (sum + ans)\), \(ans\)如果是负数,转化成模\((n-1)\)意义下的正数即可.


  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4. const int N = 1e5 + 20;
  5. int n, a[N];
  6. int main()
  7. {
  8. int __;
  9. scanf("%d", &__);
  10. while(__ --)
  11. {
  12. scanf("%d", &n);
  13. LL sum = 0, maxn = 0;
  14. for(int i = 1; i <= n; ++ i)
  15. {
  16. scanf("%d", &a[i]);
  17. sum += a[i];
  18. maxn = max(maxn, (LL)a[i]);
  19. }
  20. LL res = maxn * (n - 1) - sum;
  21. if(res < 0) res = (res % (n - 1) + (n - 1)) % (n - 1);
  22. printf("%lld\n", res);
  23. }
  24. return 0;
  25. }

C


  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int N = 2e5 + 20;
  4. char str[N];
  5. int main()
  6. {
  7. int __;
  8. scanf("%d", &__);
  9. while(__ -- )
  10. {
  11. scanf("%s", str);
  12. int res = 0, a = 0, b = 0;
  13. for(int i = 0; str[i]; ++ i)
  14. {
  15. if(str[i] == '[') a ++;
  16. if(str[i] == ']' && a) a --, res ++;
  17. if(str[i] == '(') b ++;
  18. if(str[i] == ')' && b) b --, res ++;
  19. }
  20. printf("%d\n", res);
  21. }
  22. return 0;
  23. }

D

预处理fib,求\(2^n\)的逆元即可


  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4. const int MOD = 998244353;
  5. const int N = 2e5 + 10;
  6. int n, f[N];
  7. int pow_mod(int a, int b, int p)
  8. {
  9. int res = 1;
  10. while(b)
  11. {
  12. if(b & 1) res = (LL)res * a % p;
  13. a = (LL)a * a % p;
  14. b >>= 1;
  15. }
  16. return res;
  17. }
  18. int main()
  19. {
  20. f[1] = f[2] = 1;
  21. for(int i = 3; i < N; ++ i) f[i] = (f[i - 1] + f[i - 2]) % MOD;
  22. scanf("%d", &n);
  23. int res = (LL)f[n] * pow_mod(pow_mod(2, n, MOD), MOD - 2, MOD) % MOD;
  24. printf("%d\n", res);
  25. return 0;
  26. }

2020.11.21

Educational Codeforces Round 98 (Rated for Div. 2)的更多相关文章

  1. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  2. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

  3. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

  4. Educational Codeforces Round 35 (Rated for Div. 2)

    Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...

  5. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

  6. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...

  7. Educational Codeforces Round 63 (Rated for Div. 2) 题解

    Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...

  8. Educational Codeforces Round 39 (Rated for Div. 2) G

    Educational Codeforces Round 39 (Rated for Div. 2) G 题意: 给一个序列\(a_i(1 <= a_i <= 10^{9}),2 < ...

  9. Educational Codeforces Round 48 (Rated for Div. 2) CD题解

    Educational Codeforces Round 48 (Rated for Div. 2) C. Vasya And The Mushrooms 题目链接:https://codeforce ...

随机推荐

  1. IIS Web API 长时间不连接后第一次访问非常缓慢

    搭建在 IIS 上的 Web API 若长时间不访问,会出现第一次访问耗时较长的现象,这与其调用应用程序池的 Idle Time-out(minutes) 即闲置超时设置有关.默认值为20,修改为0即 ...

  2. Python 遭遇 ProxyError 问题记录

    最近遇到的一个问题,在搞清楚之后才发现这么多年的 HTTPS_PROXY 都配置错了! 起因 想用 Python 在网上下载一些图片素材,结果 requests 报错 requests.excepti ...

  3. GitHub Actions 支持 "skip ci" 了

    GitHub Actions 支持 "skip ci" 了 Intro GitHub Actions 作为 GitHub 官方的 CI 支持,很多开源项目已经在使用 Actions ...

  4. 手撕 part1

    1.宏定义三个数最大值 挺有意思 max((a), (b), (c)) (a) > (b)? ((a) > (c)? (a) : (c)) ((b) > (c)? (b) : (c) ...

  5. JavaScript常见笔试题分析

      1.Javascript的typeof可能返回的结果有哪些? 答:共6种,具体为number ,boolean,string,undefined,function,object(对象或者null返 ...

  6. webpack 性能优化 dll 分包

    webpack 性能优化 dll 分包 html-webpack-externals-plugin DLLPlugin https://www.webpackjs.com/configuration/ ...

  7. npm publish bug & solution

    npm publish bug & solution npm ERR! Unexpected token < in JSON at position 0 while parsing ne ...

  8. Apple Watch Series 6 屏幕误触放大后无法还原问题和解决方案

    Apple Watch Series 6 屏幕误触放大后无法还原问题和解决方案 shit Apple,只能放大,不能缩小! 解决方案 关闭缩放功能 https://support.apple.com/ ...

  9. 如何用 js 实现一个 bind 函数

    如何用 js 实现一个 bind 函数 原理 实现方式 总结 refs https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referenc ...

  10. how to watch vuex state update

    how to watch vuex state update watch https://vuex.vuejs.org/api/#watch https://vuex.vuejs.org/guide/ ...