Educational Codeforces Round 118 (Rated for Div. 2)/C. Poisoned Dagger
记录自己两个月前打CF以来第一个在时限内过掉的C题(好耶!)
简单二分
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
ull a[105];
ull b[105];
ull n,h;
bool check(ull mid){
ull ans=0;
for (int i=1;i<=n;i++){
if (b[i]>=mid) ans+=mid;
else ans+=b[i];
}
if (ans>=h) return true;
else return false;
}
ll find(ull l,ull r){
if (l==r) return l;
if ((r-l)==1){
if (check(l)) return l;
else return r;
}
ull mid=(l+r)/2;
ull ans=0;
for (int i=1;i<=n;i++){
if (b[i]>=mid) ans+=mid;
else ans+=b[i];
}
if (ans==h) return mid;
if (ans>h) return find(l,mid);
if (ans<h) return find(mid,r);
}
void work(){
cin>>n;
cin>>h;
ull minn=1e9+1,maxn=0;//看数据范围,最大1e9
if (n==2) minn=1;//如果只有两次攻击,那么攻击间断区
//间就只有一个,所以最小认为是1,其实和后面的判定重合了
ull ans=0;
for (int i=1;i<=n;i++){
cin>>a[i];
if (i>=2){
b[i-1]=a[i]-a[i-1];//记录攻击间断区间的长度
if (minn>b[i-1]) minn=b[i-1];
if (maxn<b[i-1]) maxn=b[i-1];
ans+=b[i-1];
}
}
b[n]=maxn;
ans+=maxn;//先假设药效是maxn
if (ans==h){
cout<<maxn<<'\n';
return;
}
if (ans<h){
ans-=maxn;
cout<<h-ans<<'\n';
return;
}
if (check(minn)){
if (minn==1) {
cout<<1<<'\n';
return;
}
else {
cout<<find(1,minn)<<'\n';
return;
}
}
cout<<find(minn,maxn)<<'\n';
return;
}
int main(){
ios::sync_with_stdio(false);
int t;
cin>>t;
while (t--){
work();
}
return 0;
}
Educational Codeforces Round 118 (Rated for Div. 2)/C. Poisoned Dagger相关推荐
- Educational Codeforces Round 118 (Rated for Div. 2) C. Poisoned Dagger(二分或搜索)
C. Poisoned Dagger 题意: Monocarp is playing yet another computer game. In this game, his character ha ...
- 【CodeForces】Educational Codeforces Round 118 (Rated for Div. 2)【A-C】
A. Long Comparison 思路 先判断字符长度 相等的字符长度判断填满0后判断字典序 AC代码 #pragma GCC optimize("Ofast") #pragm ...
- Educational Codeforces Round 118 (Rated for Div. 2) A-C
D的难度跨度太大了,先不写了. A. Long Comparison 给出一个数字x1,后面添加p1个0,一个数字x2,后面添加p2个0.比较两个数字的大小,输出比较的情况. x和p都是10的6次方的 ...
- Educational Codeforces Round 114 (Rated for Div. 2) (A ~ F)全题解
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Educational Codeforces Round 114 (Rated for Div. 2) ...
- Educational Codeforces Round 106 (Rated for Div. 2)(A ~ E)题解(每日训练 Day.16 )
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 Educational Codeforces Round 106 (Rated for Div. ...
- Educational Codeforces Round 37 (Rated for Div. 2) 1
Educational Codeforces Round 37 (Rated for Div. 2) A.Water The Garden 题意:Max想给花园浇水.花园可被视为长度为n的花园床,花园 ...
- Educational Codeforces Round 90 (Rated for Div. 2)(A, B, C, D, E)
Educational Codeforces Round 90 (Rated for Div. 2) Donut Shops 思路 分三种情况: a==c/ba == c / ba==c/b这个时候两 ...
- Educational Codeforces Round 89 (Rated for Div. 2)(A, B, C, D)
Educational Codeforces Round 89 (Rated for Div. 2) A. Shovels and Swords 思路 题意非常简单,就是得到最多的物品嘛,我们假定a, ...
- Educational Codeforces Round 114 (Rated for Div. 2) D. The Strongest Build 暴力 + bfs
传送门 文章目录 题意: 思路: 题意: 你有nnn个装备槽,每个槽里面有cic_ici个力量加成,对于每个槽只能选一个力量加成,现在给你mmm个力量组合[b1,b2,...,bn][b_1,b_2 ...
最新文章
- XAML实例教程系列 - 命名空间(NameSpace)
- 经济学家会用到的计算机软件,大家认为社会科学不是科学而是学科的原因何在?...
- python3下载教程-《Python3从入门到放弃》视频教程
- Linux 4.0 里,你可能再也不需要重启你的操作系统。
- B端会员模块的思考与设计
- win7下设置无线上网
- boost::math模块计算二项式随机变量的概率和分位数的简单示例
- maven deploy plugin_Maven工程概念和关系
- SAP Spartacus split view右边视图的overflow属性三种不同的值
- linux引导过程和服务控制
- js获取url,截取url参数,截取url后文件名
- python3语法错误python_关于在python3.7当中的语法错误!
- 表面粗糙度的基本评定参数是_表面粗糙度100个常见问题
- 基于Python的信用评分卡模型分析(强烈推荐)
- 天然产物数据库综述:2020年从哪里找天然产物数据
- 怎么用python编写个apk_python写apk
- arduino 超声波测距原理_[Arduino]超声波测距
- VIO_FUSION
- 使用express+vue在网页上显示RTSP流视频
- 数仓工具—Hive实战之 UDF GIS(16)