Educational Codeforces Round 95 (Rated for Div. 2)
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)的更多相关文章
- Educational Codeforces Round 95 (Rated for Div. 2) C. Mortal Kombat Tower (DP)
题意:你和基友两人从左往右轮流打怪兽,强怪用\(1\)表示,垃圾用\(0\)表示,但基友比较弱,打不过强怪,碰到强怪需要用一次魔法,而你很强,无论什么怪都能乱杀,基友先打,每人每次至少杀一个怪兽,最多 ...
- Educational Codeforces Round 95 (Rated for Div. 2) B. Negative Prefixes (贪心,构造)
题意:给你一串长度为\(n\)的序列,有的位置被锁上了,你可以对没锁的位置上的元素任意排序,使得最后一个\(\le0\)的前缀和的位置最小,求重新排序后的序列. 题解:贪心,将所有能动的位置从大到小排 ...
- Educational Codeforces Round 95 (Rated for Div. 2) A. Buying Torches (数学)
题意:刚开始你有一个木棍,造一个火炬需要一个木根和一个煤块,现在你可以用一个木棍换取\(x\)个木棍,或者\(y\)根木棍换一个煤块,消耗一次操作,问最少需要操作多少次才能造出\(k\)把火炬. 题解 ...
- 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 ...
- 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 ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
- Educational Codeforces Round 35 (Rated for Div. 2)
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...
- 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 ...
- 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 ...
随机推荐
- 原创-公司项目部署交付环境预检查shell脚本
大型项目环境预检查脚本,根据自己实际情况修改脚本中变量,给大家一个思路~ #!/usr/bin/env bash root=$( cd $(dirname $0) pwd ) source " ...
- ios7.1发布企业证书测试包的问题
关于升级了ios7.1之后发布企业版证书的测试包不能下载的问题,这个苹果也挺坑的,什么都不说,也不警告一下,直接就不能用了 用xcode的organizer里面的console里发现安装的时候提示这个 ...
- selenium-自动化测试51job网站(MacOS + Safari)2020年10月6日
登录 51job ,http://www.51job.com 输入搜索关键词 "python", 地区选择 "杭州"(注意,如果所在地已经选中其他地区,要去掉) ...
- Java知识系统回顾整理01基础04操作符02关系操作符
一.关系操作符 关系操作符:比较两个变量之间的关系 > 大于 >= 大于或等于 < 小于 <= 小于或等于 == 是否相等 != 是否不等 public class Hell ...
- Android设备上的逐像素碰撞检测
介绍 我正在我的Android设备上开发一款游戏,不用说,因为我想要接触到尽可能多的用户,我做到了 省略了硬件加速.因此,我需要编写能够在大多数设备上运行的最快的代码.我从一个简单的表面视图开始 并使 ...
- 关于ptype_all和pypte_base中的pt_prev的说明[转]
不知道原帖,我是从这里看到了,解决了迷惑我很久的疑问,抄过来. 看见noble_shi兄弟"关于net_rx_action函数的若干问题"贴中关于pt_prev的问题, 本来想在论 ...
- MeteoInfoLab脚本示例:计算垂直螺旋度
尝试编写MeteoInfoLab脚本计算垂直螺旋度,结果未经验证. 脚本程序: print 'Open data files...' f_uwnd = addfile('D:/Temp/nc/uwnd ...
- Gradle的构建过程都不会?带你全面了解Android如何自定义Gradle 插件
目前 Android 工程的默认构建工具为 Gradle,我们在构建 APK 的时候往往会执行 ./gradlew assembleDebug 这样的命令.. 那么这个命令到底代表着什么含义呢?命令的 ...
- day54 Pyhton 前端JS06
内容回顾 - ECMAScript5.0 基础语法 - var 声明变量 - 五种基本数据类型 - string - number NaN number 1 number - boolean - un ...
- day37 Pyhton 网络编程04
# tcp协议和udp协议的选择问题 # tcp # 大量的连续的数据 传递文件\发送邮件 # 文件的传递 # 下载电影 # udp # 短消息类 社交软件 # qq 微信 # 在线播放视频 快会丢帧 ...