题目

题目描述
Mr. Kitayuta’s garden is planted with nn bamboos. (Bamboos are tall, fast-growing tropical plants with hollow stems.) At the moment, the height of the ii -th bamboo is h_{i}h
i

meters, and it grows a_{i}a
i

meters at the end of each day.

Actually, Mr. Kitayuta hates these bamboos. He once attempted to cut them down, but failed because their stems are too hard. Mr. Kitayuta have not given up, however. He has crafted Magical Hammer with his intelligence to drive them into the ground.

He can use Magical Hammer at most kk times during each day, due to his limited Magic Power. Each time he beat a bamboo with Magical Hammer, its height decreases by pp meters. If the height would become negative by this change, it will become 00 meters instead (it does not disappear). In other words, if a bamboo whose height is hh meters is beaten with Magical Hammer, its new height will be max(0,h-p)max(0,h−p) meters. It is possible to beat the same bamboo more than once in a day.

Mr. Kitayuta will fight the bamboos for mm days, starting today. His purpose is to minimize the height of the tallest bamboo after mm days (that is, mm iterations of “Mr. Kitayuta beats the bamboos and then they grow”). Find the lowest possible height of the tallest bamboo after mm days.

输入格式
The first line of the input contains four space-separated integers nn , mm , kk and pp ( 1<=n<=10{5},1<=m<=5000,1<=k<=10,1<=p<=10{9}1<=n<=10
5
,1<=m<=5000,1<=k<=10,1<=p<=10
9
). They represent the number of the bamboos in Mr. Kitayuta’s garden, the duration of Mr. Kitayuta’s fight in days, the maximum number of times that Mr. Kitayuta beat the bamboos during each day, and the power of Magic Hammer, respectively.

The following nn lines describe the properties of the bamboos. The ii -th of them ( 1<=i<=n1<=i<=n ) contains two space-separated integers h_{i}h
i

and a_{i}a
i

( 0<=h_{i}<=10{9},1<=a_{i}<=10{9}0<=h
i

<=10
9
,1<=a
i

<=10
9
), denoting the initial height and the growth rate of the ii -th bamboo, respectively.

输出格式
Print the lowest possible height of the tallest bamboo after mm days.

题意翻译
给定 nn 个数 h_{1 \dots n}h
1…n


你需要进行 mm 轮操作,每轮操作为 kk 次修改,每次修改可以选择一个数 h_ih
i

修改为 \max(h_i - p, 0)max(h
i

−p,0)。
每轮操作后每个 h_ih
i

将会被修改为 h_i + a_ih
i

+a
i


你需要最小化最终 h_{1 \dots n}h
1…n

中的最大值。
n \le 10^5n≤10
5
,m \le 5 \times 10^3m≤5×10
3
,k \le 10k≤10。
输入输出样例
输入 #1复制
3 1 2 5
10 10
10 10
15 2
输出 #1复制
17
输入 #2复制
2 10 10 1000000000
0 10
0 10
输出 #2复制
10
输入 #3复制
5 3 3 10
9 5
9 2
4 7
9 10
3 8
输出 #3复制
14

思路

我们先假设第m天后,自然生长下最高的竹子高度是max_height。那么我们经过处理后的答案一定会在区间[0,max]内。不可能超过我们最高的竹子。

此时我们假定一个最后的答案ans,然后二分查找的方法去找到正确的答案。

如果这个答案是正确的那么第m天的时候所有的竹子高度都会小于等于ans。那么前一天的最高的竹子高度就是ans-a[i]+p*times,times是我们对这个竹子处理的次数。然后再前一天一次类推。我们反向处理我们的竹子。

如果我们无论怎么处理最后这个竹子的高度还是会大于我们的预想答案ans,则说明我们的答案小了,继续在区间(ans,max]寻找。反之则在[0,ans]寻找。

代码

#include<bits/stdc++.h>
using namespace std;#define int long longint n,m,k,p;const int maxn = 1e5 + 5;int a[maxn],h[maxn];int he[maxn];struct bamboo {int ne;int id;bool operator < (const bamboo & x) const {return x.ne < ne;}//重载运算符
} bam[maxn];bool check(int x) {priority_queue <bamboo> q;
//  memset(he,x,sizeof(he));for(int i = 1; i<= n; i++)he[i] = x;//初始值for(int i = 1; i <= n; i++)if(he[i] - a[i] * m < h[i])q.push({x / a[i],i});//预处理for(int i = 1; i <= m; i++)//枚举m天for(int j = 1; j <= k; j++) {//增加k棵竹子高度if(!q.size())return 1;bamboo y = q.top();q.pop();if(y.ne < i)//无论如何都不满足return 0;he[y.id] += p;if(he[y.id] - a[y.id] * m < h[y.id])//增加后仍不满足就进堆q.push({he[y.id] / a[y.id],y.id});}return q.empty();
}signed main() {scanf("%d%d%d%d",&n,&m,&k,&p);for(int i = 1; i <= n; i++)scanf("%d%d",&h[i],&a[i]);int l = 0,r = 0;for(int i = 1; i <= n; i++)r = max(r,(h[i] + a[i] * m)):while(l < r) {int mid = l + r >> 1;if(check(mid))r = mid;elsel = mid +1;}cout << l << endl;return 0;
}

【IOI2020国家集训队作业 Part 1】CF505E Mr. Kitayuta vs. Bamboos相关推荐

  1. [CF505E]Mr. Kitayuta vs. Bamboos/[海军国际项目办公室]迷途竹林

    Mr. Kitayuta vs. Bamboos 迷途竹林事实上就是经TiwAirOAO\color{red}{TiwAirOAO}TiwAirOAO巨佬扩大数据范围强化后的版本.真的是强化了吗 不过 ...

  2. 2017国家集训队作业[agc016e]Poor Turkey

    2017国家集训队作业[agc016e]Poor Turkey 题意: 一开始有\(N\)只鸡是活着的,有\(M\)个时刻,每个时刻有两个数\(X_i,Y_i\),表示在第\(i\)个时刻在\(X_i ...

  3. CF506C Mr. Kitayuta vs. Bamboos

    CF506C Mr. Kitayuta vs. Bamboos 有nnn个竹子,第iii棵竹子第一天之前的高度是hih_ihi​,每一天的末尾会长高aia_iai​ 每一天你可以将砍kkk刀,每一刀将 ...

  4. Mr. Kitayuta vs. Bamboos

    Mr. Kitayuta vs. Bamboos 题目链接:http://codeforces.com/problemset/problem/505/E 参考:http://blog.csdn.net ...

  5. [CF506C]Mr. Kitayuta vs. Bamboos

    Description 有n个竹子,第i个竹子长度为h[i],每天的结束会长高a[i] 现在有m天,每一天可以做k次操作,每次操作可以选择一个竹子砍掉p,即高度h[i]=max(h[i]-p,0) 你 ...

  6. Mr. Kitayuta vs. Bamboos[二分+贪心][图像分析]

    文章目录 题目 思路 代码 题目 思路 首先最大值最小考虑二分,假设我们检验 xxx 但是发现检验比较难写 尝试从图像分析 那么画出来图像大致如下: 然后我们发现可以将图像上移末端重合至 (m,x)( ...

  7. CF506 C Mr. Kitayuta vs. Bamboos (贪心)

    题意 有n根竹子,初始高度是h[i],每天结束时会长高a[i],每天你可以砍K刀,一刀能减小p的高度.可以在某一天内砍相同的竹子多次.问m天结束后,最高的竹子最矮是多高. n≤1e5,k≤10,m≤5 ...

  8. BZOJ 2156 「国家集训队」星际探索(最短路)【BZOJ计划】

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 题目链接 https://hydro.ac/d/bzoj/p/2156 是 hydro 的 BZOJ ...

  9. Luogu P2619 [国家集训队2]Tree I(WQS二分+最小生成树)

    P2619 [国家集训队2]Tree I 题意 题目描述 给你一个无向带权连通图,每条边是黑色或白色.让你求一棵最小权的恰好有\(need\)条白色边的生成树. 题目保证有解. 输入输出格式 输入格式 ...

最新文章

  1. 关于python字典以下选项中描述错误的是_关于 Python 对文件的处理,以下选项中描述错误的是_学小易找答案...
  2. 计算机英语os是什么意思,os是什么意思(为什么手机系统有的叫OS)
  3. go 多线程并发 queue demo
  4. 火速围观!鹅厂中间件产品遭遇暴风吐槽
  5. Kafka的存储设计
  6. SQL、NoSQL、NewSQL,论开源之路谁主沉浮
  7. php自定义函数表格,自定义函数table()
  8. 【三维路径规划】基于matlab RRT算法无人机三维路径规划【含Matlab源码 1363期】
  9. 体系结构方案 - 临时性数据计算
  10. Linux版Flash亮相,但64位版需时间
  11. 线性代数之行列式(1) ——行列式的定义以及二阶行列式
  12. 贴吧签到php,贴吧自动签到 – 前端开发,JQUERY特效,全栈开发,vue开发
  13. MKB0805心率血压模块使用方法
  14. TP-link WR740N 升级版本备忘
  15. 计算机管理中不显示独立显卡,win10系统下检测不到独立显卡如何解决
  16. ROS学习记录(一) Plugin插件
  17. CyBRICS2019逆向 Matreshka lebel:java DES
  18. hht时频谱 matlab 乱序_【原创】用希尔伯特黄变换(HHT)求时频谱和边际谱
  19. MySQL查询满足条件的连续时间段
  20. 关于招投标项目经理需要知道什么

热门文章

  1. CTP接口开发案例(内附源码)
  2. c语言重复测试,C语言检测过零的方法--等待过零检测法
  3. 我的世界服务器的自动门怎么做,我的世界自动门怎么做
  4. Android应用架构之Retrofit
  5. 【排序算法】冒泡排序|选择排序|插入排序|希尔排序
  6. IT从业人员面试经典70问答
  7. 【国科大矩阵论】2021秋季叶世伟矩阵论考试计算题
  8. mysql查询提示_MySQL自成一派的查询提示
  9. 万字长文看看.NET的前世今生与将来
  10. IC后端物理效应WPE--Well Proximity Effect(阱临近效应)