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)的更多相关文章

  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. 过滤器,拦截器,aop区别与使用场景

    1. 什么是过滤器 过滤器,顾名思义就是起到过滤筛选作用的一种事物,只不过相较于现实生活中的过滤器,这里的过滤器过滤的对象是客户端访问的web资源,也可以理解为一种预处理手段,对资源进行拦截后,将其中 ...

  2. read()、readline()、readlines() -- Python

    文本文件:readfile.txt 详细描述: read()                  #一次性读取文本中全部的内容,以字符串的形式返回结果 readline()           #只读取 ...

  3. [Python] Pandas的delete、drop函数的用法

    目录 drop函数 Axis(轴)含义 drop用法实验 delete函数 drop函数 DataFrame.drop(labels=None, axis=0, index=None, columns ...

  4. linux repo init 遇到的问题

    问题描述: 利用repo从远程服务器上取代码时候,出现错误  fatal: cannot make .repo directory:Permission denied, 加了sudo 之后,还是不行, ...

  5. Inkscape tricks

    Draw straight lines: click pencil button -> click once on your canvas(starting point) -> click ...

  6. Koa & node.js

    KOA https://github.com/koajs/koa https://koajs.com/ $ nvm install 7 # node.js 7 + $ nvm install 10 $ ...

  7. TypeScript 如何编写类库声明文件 .d.ts

    TypeScript 如何编写类库声明文件 .d.ts how to write a d.ts file declaration-files/ https://www.typescriptlang.o ...

  8. django学习-27.admin管理后台里:对列表展示页面的数据展示进行相关优化

    目录结构 1.前言 2.完整的操作步骤 2.1.第一步:查看ModelAdmin类和BaseModelAdmin类的源码 2.2.第二步:查看表animal对应的列表展示页面默认的数据展示 2.3.第 ...

  9. django学习-20.python3中的特殊方法【__str__】的作用

    目录结构 1.前言 2.[__str__]特殊方法的具体使用 2.1.当使用print打印一个类被实例化后生成的对象的时候,若类里有定义了[__str__]特殊方法,是打印出这样的数据:[__str_ ...

  10. (十) 数据库查询处理之排序(sorting)

    1. 为什么我们需要对数据排序 可以支持对于重复元素的清除(支持DISTINCT) 可以支持GROUP BY 操作 对于关系运算中的一些运算能够得到高效的实现 2. 引入外部排序算法 对于不能全部放在 ...