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. 性能测试Jmeter安装

    一. Jmeter下载地址: http://jmeter.apache.org/download_jmeter.cgi   二. JDK下载地址: https://www.oracle.com/tec ...

  2. C#方法Extra

    C#方法Extra 上次说的只是方法的一些基本东西,今天讲讲重载和 Lambda 表达式. 重载 方法的重载(overload)指的是同一个名字的方法,有着不一样的方法签名(method signat ...

  3. Morris遍历

    Morris遍历 一种遍历二叉树的方式,并且时间复杂度O(N),额外空间复杂度O(1) 通过利用原树中大量空闲指针的方式,达到节省空间的目的 Morris遍历可以改前中后序的树遍历 思路: 创建一个当 ...

  4. SpringBoot-06-模板引擎Thymeleaf

    6. 模板引擎 Thymeleaf Thyme leaf 英译为 百里香的叶子. 模板引擎 ​ 以前开发中使用的jsp就是一个模板引擎,但是springboot 以jar的方式,并且使用嵌入式的tom ...

  5. Selenium截屏 图片未加载的问题解决--【懒加载】

    需求: 截屏后转PDF. 问题: selenium截屏后,图片未加载 如下图: 原因: 网站使用了懒加载技术:只有在浏览器中纵向滚动条滚动到指定的位置时,页面的元素才会被动态加载. 什么是图片懒加载? ...

  6. (数据科学学习手札97)掌握pandas中的transform

    本文示例文件已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 1 简介 开门见山,在pandas中,transform是 ...

  7. 多测师讲解自动化测试 _RF封装_(三层模式)高级讲师肖sir

    rf自动化:分层作用: 1.项目----有重复的流程(借款-登录,出借-登录) 2.借款--登录(8个流程)机器人:案例层(用例)写在机器人中,1个机器人=1条用例 分三个层次: 1.案例层(存放用例 ...

  8. LR Optimization-Based Estimator Design for Vision-Aided Inertial Navigation

    Abstract 我们设计了一个 hybrid 估计器, 组合了两种算法, sliding-window EKF 和 EKF-SLAM. 我们的结果表示, hybrid算法比单一的好. 1. Intr ...

  9. 解决React前端在开发环境的跨域问题

    在前后端分离的分布式架构中,跨域是一道无法绕过去的门槛,众所周知,生产环境上解决跨域最便捷的方式是使用Nginx来处理,那么,在本地开发环境又该如何处理呢? React框架里处理跨域问题,可以使用ht ...

  10. 【博弈论】51Nod 1534 棋子游戏

    题目内容 波雷卡普和瓦西里喜欢简单的逻辑游戏.今天他们玩了一个游戏,这个游戏在一个很大的棋盘上进行,他们每个人有一个棋子.他们轮流移动自己的棋子,波雷卡普先开始.每一步移动中,波雷卡普可以将他的棋子从 ...