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. vue +signalR

    概述:ASP.NET Core SignalR是一种开放源代码库,可简化将实时 web 功能添加到应用程序的功能. 实时 web 功能使服务器端代码可以立即将内容推送到客户端. 这玩意的概念我就不多讲 ...

  2. SQL Server 2008 R2执行存储过程sp_MailItemResultSets引起大量PREEMPTIVE_OS_WAITFORSINGLEOBJEC等待

      从监控工具DPA中发现一个数据库(SQL Server 2008 R2)的等待事件突然彪增,下钻分析发现数据库执行存储过程sp_MailItemResultSets时,引起了非常严重的等待(Hig ...

  3. Docker:四、Docker进阶 Windows Docker IIS 部署

    前面的三篇docker 文档大家看的肯定不过瘾,自己可能也已经上手一试了...不知道有没有发现问题... 哈哈... 我来说说我遇到的问题哦 一.windows docker 镜像越来越大 默认的do ...

  4. Linux系统编程—条件变量

    条件变量是用来等待线程而不是上锁的,条件变量通常和互斥锁一起使用.条件变量之所以要和互斥锁一起使用,主要是因为互斥锁的一个明显的特点就是它只有两种状态:锁定和非锁定,而条件变量可以通过允许线程阻塞和等 ...

  5. 我给VSCode报了个bug,微软工程师竟然凌晨回复了...

    柠檬哥整理了50本计算机相关的电子书,关注公众号「后端技术学堂」,回复「1024」即可获取,回复「进群」拉你进读者技术交流群. 本文首发个人微信公众号,欢迎围观点击阅读原文 最近遇到一个有意思的bug ...

  6. hystrix ,feign,ribbon的超时时间配置,以及原理分析

    背景,网上看到很多关于hystrix的配置都是没生效的,如: 一.先看测试环境搭建: order 服务通过feign 的方式调用了product 服务的getProductInfo 接口 //---- ...

  7. 登陆页跳出iframe

    1 if(top.location.href != location.href){ 2 top.location.href = location.href; 3 }

  8. selenium3介绍

    1.  简介 Selenium是用于测试 Web应用程序用户界面 (UI)的常用框架.它是一款用于运行端到端功能测试的超强工具.您可以使用多个编程语言编写测试,并且 Selenium能够在一个或多个浏 ...

  9. 排序算法:归并排序(Merge Sort)

    归并排序 归并排序采用了分治策略(divide-and-conquer),就是将原问题分解为一些规模较小的相似子问题,然后递归解决这些子问题,最后合并其结果作为原问题的解. 归并排序将排序数组A[1. ...

  10. 067 01 Android 零基础入门 01 Java基础语法 08 Java方法 05 数组作为方法参数

    067 01 Android 零基础入门 01 Java基础语法 08 Java方法 05 数组作为方法参数 本文知识点:数组作为方法参数 说明:因为时间紧张,本人写博客过程中只是对知识点的关键步骤进 ...