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. 国产smartbits版本-minismb测试高恪路由器IP限速

    Minismb测试仪表是复刻smartbits的国产版本,是一款专门用于测试智能路由器,网络交换机的性能和稳定性的软硬件相结合的工具.可以通过此工具测试任何ip网络设备的端口吞吐率,带宽,并发连接数和 ...

  2. python-gen

  3. K8S(07)交付实战-架构说明并准备zk集群

    k8s交付实战-架构说明并准备zk集群 目录 k8s交付实战-架构说明并准备zk集群 1 交付的服务架构图: 1.1 架构图解 1.2 交付说明: 2 部署ZK集群 2.1 二进制安装JDK 2.1. ...

  4. Kubernetes安装EFK教程(非存储持久化方式部署)

    1.简介 这里所指的EFK是指:ElasticSearch,Fluentd,Kibana ElasticSearch Elasticsearch是一个基于Apache Lucene的开源搜索和数据分析 ...

  5. C# 类 (7) - 抽象 Abstract

    Abstract 抽象类,关键字Abstract ,最典型的应用就是在 继承机制里 作为base类,抽象类是不能被实例化的(前面说的static 类也不能被实例化)它必须作为 基类,被别人继承,然后必 ...

  6. zsh terminal set infinity scroll height

    zsh terminal set infinity scroll height zsh Terminal 开启无限滚动 https://stackoverflow.com/questions/2761 ...

  7. WebXR All in One

    WebXR All in One VR / WebVR WebXR https://www.w3.org/TR/webxr/ WebXR Device API https://immersiveweb ...

  8. js & bitwise operator

    js & bitwise operator bitwise operator https://github.com/Advanced-Frontend/Daily-Interview-Ques ...

  9. better-scroll使用参考

    ************better-scroll是基于父元素固定高度,溢出才滚动的,所以父元素务必定高,否则无法滚动***************************************** ...

  10. Flutter: SliverAppBar 应用程序栏与滚动视图集成,以便它可以根据滚动偏移量在高度上变化

    API class _MyHomeState extends State<MyHome> with SingleTickerProviderStateMixin { @override W ...