Educational Codeforces Round 98 (Rated for Div. 2)
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
Educational Codeforces Round 98 (Rated for Div. 2)的更多相关文章
- 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 ...
- 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 ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
- Educational Codeforces Round 35 (Rated for Div. 2)
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...
- 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 ...
- 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 ...
- Educational Codeforces Round 63 (Rated for Div. 2) 题解
Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...
- 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 < ...
- Educational Codeforces Round 48 (Rated for Div. 2) CD题解
Educational Codeforces Round 48 (Rated for Div. 2) C. Vasya And The Mushrooms 题目链接:https://codeforce ...
随机推荐
- IIS Web API 长时间不连接后第一次访问非常缓慢
搭建在 IIS 上的 Web API 若长时间不访问,会出现第一次访问耗时较长的现象,这与其调用应用程序池的 Idle Time-out(minutes) 即闲置超时设置有关.默认值为20,修改为0即 ...
- Python 遭遇 ProxyError 问题记录
最近遇到的一个问题,在搞清楚之后才发现这么多年的 HTTPS_PROXY 都配置错了! 起因 想用 Python 在网上下载一些图片素材,结果 requests 报错 requests.excepti ...
- GitHub Actions 支持 "skip ci" 了
GitHub Actions 支持 "skip ci" 了 Intro GitHub Actions 作为 GitHub 官方的 CI 支持,很多开源项目已经在使用 Actions ...
- 手撕 part1
1.宏定义三个数最大值 挺有意思 max((a), (b), (c)) (a) > (b)? ((a) > (c)? (a) : (c)) ((b) > (c)? (b) : (c) ...
- JavaScript常见笔试题分析
1.Javascript的typeof可能返回的结果有哪些? 答:共6种,具体为number ,boolean,string,undefined,function,object(对象或者null返 ...
- webpack 性能优化 dll 分包
webpack 性能优化 dll 分包 html-webpack-externals-plugin DLLPlugin https://www.webpackjs.com/configuration/ ...
- npm publish bug & solution
npm publish bug & solution npm ERR! Unexpected token < in JSON at position 0 while parsing ne ...
- Apple Watch Series 6 屏幕误触放大后无法还原问题和解决方案
Apple Watch Series 6 屏幕误触放大后无法还原问题和解决方案 shit Apple,只能放大,不能缩小! 解决方案 关闭缩放功能 https://support.apple.com/ ...
- 如何用 js 实现一个 bind 函数
如何用 js 实现一个 bind 函数 原理 实现方式 总结 refs https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referenc ...
- how to watch vuex state update
how to watch vuex state update watch https://vuex.vuejs.org/api/#watch https://vuex.vuejs.org/guide/ ...