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 ...
随机推荐
- Educational Codeforces Round 89 (Rated for Div. 2) B. Shuffle (数学,区间)
题意:有长为\(n\)的排列,其中\(x\)位置上的数为\(1\),其余位置全为\(0\),询问\(m\)次,每次询问一个区间,在这个区间内可以交换任意两个位置上的数,问\(1\)最后出现在不同位置的 ...
- - 迷宫问题 POJ - 3984 bfs记录路径并输出最短路径
定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, ...
- win7 & centos7 双系统安装方法
1.准备 1)Centos7镜像 官方:https://www.centos.org/ 阿里镜像:http://mirrors.aliyun.com/centos/ 2)安装windows7系统的电脑 ...
- C#(winform)button去掉各种边框
仔细读完,主要在FlatAppearance属性里 1.既然是添加背景图片 所以这里应该使用 Button.BackgroudImage = "" ;来设置图片 而不应该使用 B ...
- 在异步或子线程中show窗体的时候要用MethodInvoker委托,要不然show不出来
this.Invoke((MethodInvoker)delegate () { Thread.Sleep(500); this.Hide(); FloatWnd floatWnd = new Flo ...
- 【ybt金牌导航1-2-3】折线统计
折线统计 题目链接:ybt金牌导航1-2-3 题目大意 在一个图上有一些点,保证任意两个点的横纵坐标都不相同. 要你选一些集合,按 x 坐标排序依次连接,会构成一些连续上升下降的折线,问你折线数量是 ...
- Python_小程序
一.开发前的准备工作 1.申请AppID:一个账号对应一个小程序,个人/个体只能申请5个小程序 2.下载开发工具 二.小程序的文件结构 三. 1.数据绑定 1.1数据的设置 Page( data:{ ...
- Atlas 读写分离 & Atlas + MHA 故障自动恢复
目录 Atals 介绍 Atlas 主要功能 Atlas 相对于官方 MySQL-Proxy 的优势 Atlas 使用 Atlas 安装 Atlas 目录 Atlas 配置 Atlas 启动 Atla ...
- 2018大都会赛 A Fruit Ninja【随机数】
题目链接:戳这里 题意:一个平面里有n个点,问存不存在一条直线上有m个点,满足m >= n*x. 解题思路:0<x<1,且x小数点后只有1位,也就是说10*m > n.假设存在 ...
- vue中获取元素并控制相应的dom
1 在标签中使用ref="xxx" 2 在methods中调用this.$refs.xxx this.$refs.xxx.$el获取dom 注意1:大多数情况下为了复用方法,将xx ...