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 ...
随机推荐
- 踏上Revit二次开发之路 0 序
0 序 近来,由于工作上的需要,开始自学Revit二次开发. Revit由欧特克公司专为BIM构建,是建筑业体系中使用最广泛的软件之一.借助欧特克公司在我国市场占有率方面的绝对优势,甚至给不少人带来& ...
- OpenStack Train版-1.安装基础环境&服务
1. 服务组件的密码 密码名称 描述 ADMIN_PASS admin用户密码 CINDER_DBPASS 块设备存储服务的数据库密码 CINDER_PASS 块设备存储服务的 cinder 密码 D ...
- ArcGIS Mobile 自定义图层在绘制面时节点未绘制完全的问题
ArcGIS Mobile 自定义图层在绘制面时节点未绘制完全,如下图: 面的绘制代码如下: public void Draw(Display dis, Pen p1, Pen p2,Pen p3 , ...
- cookie,session,token之间的联系与区别
发展史 1.很久很久以前,Web 基本上就是文档的浏览而已, 既然是浏览,作为服务器, 不需要记录谁在某一段时间里都浏览了什么文档,每次请求都是一个新的HTTP协议, 就是请求加响应, 尤其是我不用 ...
- java8按照lamda表达式去重一个list,根据list中的一个元素
/** * 按照指定字段给list去重 * @param list * @return */ public static List<DataModel> niqueList(List< ...
- Gym 100796B Wet Boxes(思维)题解
题意:给一个如图坐标系,每个方形都放在下面两个中间,已知一个木块湿了那么他下面所有的都会湿,显然,不能湿两次.问,每次给出一个坐标,把他弄湿,有几个木块从干变成湿了. 思路:我们把坐标系拉直,就变成了 ...
- 7816协议时序和采用UART模拟7816时序与智能卡APDU指令协议
7816时序 7816时一个比较早的老通讯时序了,最近项目上需要用UART模拟所以,简单学习时序. 时序比较简单,熟悉UART的一眼看着就像是串口的时序,只是他没有停止位,取而代之的就是保护时间gur ...
- bind & this & new & arrow function
bind & this & new & arrow function this bind call apply new arrow function arrow functio ...
- js & touch & swiper
js & touch & swiper https://developer.mozilla.org/en/docs/Web/API/Touch_events "use str ...
- React In Depth
React In Depth React Component Lifecycle https://reactjs.org/docs/react-component.html https://react ...