A

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


#include <bits/stdc++.h>
using namespace std; int n, m; int main()
{
int __;
scanf("%d", &__);
while(__ -- )
{
scanf("%d%d", &n, &m);
printf("%d\n", 2 * max(n, m) - (m != n));
}
return 0;
}

B

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


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e5 + 20; int n, a[N]; int main()
{
int __;
scanf("%d", &__);
while(__ --)
{
scanf("%d", &n);
LL sum = 0, maxn = 0;
for(int i = 1; i <= n; ++ i)
{
scanf("%d", &a[i]);
sum += a[i];
maxn = max(maxn, (LL)a[i]);
}
LL res = maxn * (n - 1) - sum;
if(res < 0) res = (res % (n - 1) + (n - 1)) % (n - 1);
printf("%lld\n", res);
}
return 0;
}

C


#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 20; char str[N]; int main()
{
int __;
scanf("%d", &__);
while(__ -- )
{
scanf("%s", str);
int res = 0, a = 0, b = 0;
for(int i = 0; str[i]; ++ i)
{
if(str[i] == '[') a ++;
if(str[i] == ']' && a) a --, res ++;
if(str[i] == '(') b ++;
if(str[i] == ')' && b) b --, res ++;
}
printf("%d\n", res);
}
return 0;
}

D

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


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MOD = 998244353;
const int N = 2e5 + 10; int n, f[N]; int pow_mod(int a, int b, int p)
{
int res = 1;
while(b)
{
if(b & 1) res = (LL)res * a % p;
a = (LL)a * a % p;
b >>= 1;
}
return res;
} int main()
{
f[1] = f[2] = 1;
for(int i = 3; i < N; ++ i) f[i] = (f[i - 1] + f[i - 2]) % MOD;
scanf("%d", &n);
int res = (LL)f[n] * pow_mod(pow_mod(2, n, MOD), MOD - 2, MOD) % MOD;
printf("%d\n", res);
return 0;
}

2020.11.21

最新文章

  1. 谈谈JS中的函数节流
  2. aspx页面常用代码
  3. JAVA单例的三种实现方式
  4. 一些sql三
  5. sqlserver2012相关资源下载
  6. DEV--GerdView控件
  7. .net ajax式上传文件
  8. 採集和输出 DeckLink Studio 4K
  9. AsyncSocket 使用
  10. POJ 4003 Bob’s Race &amp;&amp; HDU4123 Bob’s Race (dfs+rmq)
  11. thinkphp学习笔记6—url模式
  12. mysql性能优化配置总结
  13. webpack 2.x 配置
  14. RobotFramework自动化测试框架-移动手机自动化测试Click A Point关键字的使用
  15. ndk编译ffmpeg
  16. Exp6 信息搜集与漏洞扫描 20164313 杜桂鑫
  17. Docker Kubernetes 介绍 or 工作原理
  18. gets函数
  19. js将字符串转json
  20. 【mysql】创建索引

热门文章

  1. BKDR字符串哈希
  2. 深入了解gradle和maven的区别
  3. LINUX - 文件读写缓存
  4. USB2.0协议学习笔记---USB工作过程(类的方法)
  5. React Query &amp; SWR
  6. How to build a sortable table in native js?
  7. Chart.js &amp; CPU 性能监控
  8. 如何配置 webpack 支持 preload, prefetch, dns-prefetch
  9. GitHub Packages
  10. npm &amp; private npm service &amp; nrm &amp; nvm