CF的Educational Round (Div.2),质量还是蛮高的。

A: 水题

#include<cstdio>
#include<algorithm>
typedef long long ll;
ll T,x,y,k,ans; template <typename T>
inline void read(T &x){
char ch = getchar(); x = 0; int f = 1;
for(;ch > '9' || ch < '0'; ch = getchar()) if(ch == '-') f = -1;
for(;ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - 48;
x *= f;
}
int main(){
read(T);
while(T--){
read(x); read(y); read(k);
ans = y * k + k - 1; x--;
if(ans % x == 0) printf("%lld\n",ans / x + k);
else printf("%lld\n",ans / x + k + 1);
}
return 0;
}

B: 降序排序没被固定的元素,挨个替换没被固定的元素。

#include<cstdio>
#include<algorithm>
#include<functional>
typedef long long ll;
int T,n,m,t = 0;
int a[110],b[110];
bool vis[110]; template <typename T>
inline void read(T &x){
char ch = getchar(); x = 0; int f = 1;
for(;ch > '9' || ch < '0'; ch = getchar()) if(ch == '-') f = -1;
for(;ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - 48;
x *= f;
}
int main(){
read(T);
while(T--){
read(n); m = t = 0;
for(int i = 1;i <= n; i++) read(a[i]);
for(int i = 1;i <= n; i++) read(vis[i]);
for(int i = 1;i <= n; i++)
if(!vis[i])
b[++m] = a[i];
std::sort(b + 1,b + m + 1,std::greater <int>());
for(int i = 1;i <= n; i++)
if(!vis[i])
a[i] = b[++t];
for(int i = 1;i <= n; i++) printf("%d ",a[i]);
printf("\n");
}
return 0;
}

C: 显而易见的dp。

#include<cstdio>
#include<algorithm>
typedef long long ll;
const int M = 200010;
int T,n;
int a[M];
int dp[M][2];//0表示当前是我到达这里,1表示是朋友到达 template <typename T>
inline void read(T &x){
char ch = getchar(); x = 0; int f = 1;
for(;ch > '9' || ch < '0'; ch = getchar()) if(ch == '-') f = -1;
for(;ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - 48;
x *= f;
}
int main(){
read(T);
while(T--){
read(n);
for(int i = 1;i <= n; i++) read(a[i]), dp[i][0] = dp[i][1] = M;
dp[1][1] = a[1]; dp[2][1] = a[1] + a[2];
dp[2][0] = a[1];
for(int i = 3;i <= n; i++){
dp[i][0] = std::min(dp[i - 2][1],dp[i - 1][1]);
dp[i][1] = std::min(dp[i - 2][0] + a[i - 1] + a[i],dp[i - 1][0] + a[i]);
}
printf("%d\n",std::min(dp[n][1],dp[n][0]));
}
return 0;
}

D: 结论非常明显,由于是删除一个位置所有的垃圾,所以可以用可以去重的set存下当前有垃圾的位置。

然后因为要求聚拢垃圾到不超过2个堆里,则可以转换为相邻垃圾间的距离,即为dis[i] = set[i + 1] - set[i],可以用multiset存储。

所以对于每一个状态,答案便是*set.(--s.end()) - *s.begin() - *(--ms.end()) 。

细节看代码。

#include<cstdio>
#include<algorithm>
#include<set>
typedef long long ll;
const int M = 100010;
int n,q;
int a[M]; template <typename T>
inline void read(T &x){
char ch = getchar(); x = 0; int f = 1;
for(;ch > '9' || ch < '0'; ch = getchar()) if(ch == '-') f = -1;
for(;ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - 48;
x *= f;
}
std::set <int> s;
std::multiset <int> ms;
int main(){
read(n); read(q);
for(int i = 1;i <= n; i++) read(a[i]), s.insert(a[i]);
std::sort(a + 1,a + n + 1);
for(int i = 2;i <= n; i++) ms.insert(a[i] - a[i - 1]);
printf("%d\n",(s.size() <= 2) ? 0 : *(--s.end()) - *s.begin() - *(--ms.end()));
while(q--){
int t,x;
read(t); read(x);
if(t == 0){
std::set <int>::iterator it = s.find(x), l = it, r = it;
l--; r++;
if(it != s.begin()) ms.erase(ms.find(x - *l));
if(it != --s.end()) ms.erase(ms.find(*r - x));
if(it != s.begin() && it != --s.end()) ms.insert(*r - *l);
s.erase(it);
}
else{
s.insert(x);
std::set <int>::iterator it = s.find(x), l = it, r = it;
l--; r++;
if(it != s.begin()) ms.insert(x - *l);
if(it != --s.end()) ms.insert(*r - x);
if(it != s.begin() && it != --s.end()) ms.erase(ms.find(*r - *l));
}
printf("%d\n",(s.size() <= 2) ? 0 : *(--s.end()) - *s.begin() - *(--ms.end()));
}
return 0;
}

E: 思想非常明显,直接lower_bound二分出所有比防御力高的怪的数量,然后分类计算。

细节见代码。

#include <cstdio>
#include <algorithm>
typedef long long ll;
const int M = 200010, mod = 998244353;
int n, q, dura, def, ans;
int a[M],sum[M]; template <typename T>
inline void read(T &x){
char ch = getchar(); x = 0; int f = 1;
for(;ch > '9' || ch < '0'; ch = getchar()) if(ch == '-') f = -1;
for(;ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - 48;
x *= f;
}
inline int q_pow(int x,int num){
int ret = 1;
for(;num; num >>= 1){
if(num & 1) ret = 1ll * ret * x % mod;
x = 1ll * x * x % mod;
}
return ret;
}
int main(){
read(n); read(q);
for(int i = 1;i <= n; i++) read(a[i]);
std::sort(a + 1,a + n + 1);
for(int i = 1;i <= n; i++) sum[i] = (sum[i - 1] + a[i]) % mod;
while(q--){
read(dura); read(def); ans = 0;
int x = std::lower_bound(a + 1,a + n + 1,def) - a;
int smallsum = sum[x - 1], bigsum = sum[n] - sum[x - 1];
x = n - x + 1;//可以破防的数目
if(dura <= x){
ans = 1ll * bigsum * (x - dura) % mod * q_pow(x,mod - 2) % mod;
ans = (ans + 1ll * smallsum * (x - dura + 1) % mod * q_pow(x + 1,mod - 2)) % mod;
}
printf("%d\n",ans);
}
return 0;
}

F: 不会。。。

G: 想法太假了,没想到线段树上。

Educational Codeforces Round 95 (Rated for Div. 2)的更多相关文章

  1. Educational Codeforces Round 95 (Rated for Div. 2) C. Mortal Kombat Tower (DP)

    题意:你和基友两人从左往右轮流打怪兽,强怪用\(1\)表示,垃圾用\(0\)表示,但基友比较弱,打不过强怪,碰到强怪需要用一次魔法,而你很强,无论什么怪都能乱杀,基友先打,每人每次至少杀一个怪兽,最多 ...

  2. Educational Codeforces Round 95 (Rated for Div. 2) B. Negative Prefixes (贪心,构造)

    题意:给你一串长度为\(n\)的序列,有的位置被锁上了,你可以对没锁的位置上的元素任意排序,使得最后一个\(\le0\)的前缀和的位置最小,求重新排序后的序列. 题解:贪心,将所有能动的位置从大到小排 ...

  3. Educational Codeforces Round 95 (Rated for Div. 2) A. Buying Torches (数学)

    题意:刚开始你有一个木棍,造一个火炬需要一个木根和一个煤块,现在你可以用一个木棍换取\(x\)个木棍,或者\(y\)根木棍换一个煤块,消耗一次操作,问最少需要操作多少次才能造出\(k\)把火炬. 题解 ...

  4. 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 ...

  5. 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 ...

  6. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

  7. Educational Codeforces Round 35 (Rated for Div. 2)

    Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. [BJDCTF2020]EzPHP

    [BJDCTF2020]EzPHP 解码:http://794983a5-f5dc-4a13-bc0b-ca7140ba23f3.node3.buuoj.cn/1nD3x.php 源代码: <? ...

  2. NLP常见任务

    借助BERT论文, 梳理下自然语言处理当前常见的任务. NLP任务 根据判断主题的级别, 将所有的NLP任务分为两种类型: token-level task: token级别的任务. 如完形填空(Cl ...

  3. 1.UiPath账密安全保存常见方法

    今天在写流程的时候突然用到密码保存,看到同事不同项目中所用到的方法不同,就看了一下别的同学博客,总结的特别好,自己跟着实操了一遍,受益匪浅. RPA适合于登录不同的系统代替人工操作,而登录系统时难免要 ...

  4. Python-信号量和线程池-semaphore ThreadPollExector

    信号量 其实本质上是锁,Lock是单锁,信号量是指定多把锁,也就是说通过信号量指定多个数线程可以访问相同资源,一般情况下读操作可以有多个,但写操作同时只有一个 信号量模块 semaphore # 使用 ...

  5. OpenCV图像处理学习笔记-Day4(完结)

    OpenCV图像处理学习笔记-Day4(完结) 第41课:使用OpenCV统计直方图 第42课:绘制OpenCV统计直方图 pass 第43课:使用掩膜的直方图 第44课:掩膜原理及演示 第45课:直 ...

  6. Android 自定义Vie 对勾CheckBox

    天在美团点外卖,有一个商品推荐的条目,上面的CheckBox是自定义的,虽然我们大部分都是用图片来自定义样式.但是还是可以自定义View来绘制的,只要画一个圆和对勾即可. 最终效果 最终效果.png ...

  7. 《kubernetes + .net core 》dev ops部分

    目录 1.kubernetes 预备知识 1.1 集群资源 1.1.1 role 1.1.2 namespace 1.1.3 node 1.1.4 persistent volume 1.1.5 st ...

  8. matplotlib绘图教程,设置标签与图例

    大家好,欢迎大家阅读周四数据处理专题,我们继续介绍matplotlib作图工具. 在上一篇文章当中我们介绍了matplotlib这个包当中颜色.标记和线条这三种画图的设置,今天我们同样也介绍三种新的设 ...

  9. The Python Tutorial 和 documentation和安装库lib步骤

    链接: The Python Tutorial : https://docs.python.org/3.6/tutorial/index.html Documentation: https://doc ...

  10. c中_tmain()和main()区别

    来源参考:https://www.cnblogs.com/lucyjiayou/archive/2011/05/07/2039621.html tchar.h>可以找到,如#define _tm ...