POJ_3104_Drying_(二分,最小化最大值)
描述
http://poj.org/problem?id=3104
n件衣服,第i件衣服里面有水a[i],自然风干每分钟干1个水,用吹风机每分钟干k个水,但是同时只能对一件衣服使用吹风机,求干完所有衣服所需时间的最小值.
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 12639 | Accepted: 3256 |
Description
It is very hard to wash and especially to dry clothes in winter. But Jane is a very smart girl. She is not afraid of this boring process. Jane has decided to use a radiator to make drying faster. But the radiator is small, so it can hold only one thing at a time.
Jane wants to perform drying in the minimal possible time. She asked you to write a program that will calculate the minimal time for a given set of clothes.
There are n clothes Jane has just washed. Each of them took ai water during washing. Every minute the amount of water contained in each thing decreases by one (of course, only if the thing is not completely dry yet). When amount of water contained becomes zero the cloth becomes dry and is ready to be packed.
Every minute Jane can select one thing to dry on the radiator. The radiator is very hot, so the amount of water in this thing decreases by k this minute (but not less than zero — if the thing contains less than k water, the resulting amount of water will be zero).
The task is to minimize the total time of drying by means of using the radiator effectively. The drying process ends when all the clothes are dry.
Input
The first line contains a single integer n (1 ≤ n ≤ 100 000). The second line contains ai separated by spaces (1 ≤ ai ≤ 109). The third line contains k (1 ≤ k ≤ 109).
Output
Output a single integer — the minimal possible number of minutes required to dry all clothes.
Sample Input
sample input #1
3
2 3 9
5 sample input #2
3
2 3 6
5
Sample Output
sample output #1
3 sample output #2
2
Source
分析
二分.
最小化最大值.
y为原来的最大时间.然后二分可行时间x,如果有自然风干时间>x的,用吹分机加速,多出的时间用多的速度弥补,并向上取整,看吹风机是否够用.
注意:
1.k=1时,v=k-1=0,不能做除数.............要特判.........
#include<cstdio>
#include<algorithm>
using std :: max; const int maxn=;
int n,k,x,y;
int a[maxn]; bool C(int x)
{
int rest=x;
for(int i=;i<=n;i++)
{
if(a[i]>x)
{
int d=a[i]-x;
int v=k-;
int res=d/v;
if(d%v!=) res++;
rest-=res;
}
if(rest<) return false;
}
return true;
} void solve()
{
while(x<y)
{
int m=x+(y-x)/;
if(C(m)) y=m;
else x=m+;
}
printf("%d\n",x);
} void init()
{
scanf("%d",&n);
for(int i=;i<=n;i++) { scanf("%d",&a[i]); y=max(y,a[i]); }
scanf("%d",&k);
} int main()
{
freopen("dry.in","r",stdin);
freopen("dry.out","w",stdout);
init();
if(k==)
{
printf("%d\n",y);
return ;
}
solve();
fclose(stdin);
fclose(stdout);
return ;
}
POJ_3104_Drying_(二分,最小化最大值)的更多相关文章
- POJ_3273_Monthly_Expense_(二分,最小化最大值)
描述 http://poj.org/problem?id=3273 共n个月,给出每个月的开销.将n个月划分成m个时间段,求m个时间段中开销最大的时间段的最小开销值. Monthly Expense ...
- Monthly Expense(二分--最小化最大值)
Farmer John is an astounding accounting wizard and has realized he might run out of money to run the ...
- POJ3273-Monthly Expense (最小化最大值)
题目链接:cid=80117#problem/E">click here~~ [题目大意] 农夫JF在n天中每天的花费,要求把这n天分作m组.每组的天数必定是连续的.要求分得各组的花费 ...
- poj 3273 Monthly Expense (二分搜索,最小化最大值)
题目:http://poj.org/problem?id=3273 思路:通过定义一个函数bool can(int mid):=划分后最大段和小于等于mid(即划分后所有段和都小于等于mid) 这样我 ...
- OJ 21658::Monthly Expense(二分搜索+最小化最大值)
Description Farmer John是一个令人惊讶的会计学天才,他已经明白了他可能会花光他的钱,这些钱本来是要维持农场每个月的正常运转的.他已经计算了他以后N(1<=N< ...
- POJ 3273 Monthly Expense二分查找[最小化最大值问题]
POJ 3273 Monthly Expense二分查找(最大值最小化问题) 题目:Monthly Expense Description Farmer John is an astounding a ...
- [ACM] POJ 3273 Monthly Expense (二分解决最小化最大值)
Monthly Expense Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 14158 Accepted: 5697 ...
- 第十四届华中科技大学程序设计竞赛 K Walking in the Forest【二分答案/最小化最大值】
链接:https://www.nowcoder.com/acm/contest/106/K 来源:牛客网 题目描述 It's universally acknowledged that there'r ...
- 洛谷 P1462 通往奥格瑞玛的道路 Label: 最小化最大值 && spfa (存多条边示例)
题目背景 在艾泽拉斯大陆上有一位名叫歪嘴哦的神奇术士,他是部落的中坚力量 有一天他醒来后发现自己居然到了联盟的主城暴风城 在被众多联盟的士兵攻击后,他决定逃回自己的家乡奥格瑞玛 题目描述 在艾泽拉斯, ...
随机推荐
- tomcat启动正常,404. Eclipse没有正确部署工程项目
http://blog.csdn.net/lynn_wgr/article/details/7751228 在eclipse中新建的Dynamic Web Project.写好代码后,选择Run on ...
- AVAudioSession 的 AVAudioSessionCategory 和 AVAudioSessionCategoryOptions 相关
AVAudioSessionCategory相关 AVAudioSessionCategoryAmbient 使用这个category的应用会随着静音键和屏幕关闭而静音.并且不会中止其它应用播放声音, ...
- myeclipse启动报JVM terminated. Exit code=1
报错信息如图: 解决办法: 删除当前workspaces下文件夹,路径为:%Workspaces%/.metadata/.plugins/org.eclipse.core.runtime
- [USACO1.1.4]坏掉的项链Broken Necklace
P1203 [USACO1.1]坏掉的项链Broken Necklace 标签 搜索/枚举 USACO 难度 普及- 题目描述 你有一条由N个红色的,白色的,或蓝色的珠子组成的项链(3<=N&l ...
- Launch a Batch File With Windows Installer
Quote from: http://flexerasoftware.force.com/articles/en_US/HOWTO/Q111515 Synopsis This article desc ...
- 原型模式(Prototype Pattern)
原型模型:用于创建重复对象,同时保证性能. 这种模式实现一个原型接口,用于创建对象的克隆,当直接创建对象的代价比较大,则可以采用这种模式.例如:一个对象需要高代价的数据库操作之后被创建,这时可以缓存该 ...
- IOS 学习笔记 2015-03-18
Objective--C 一 关键字 1 KVC 动态设值,动态取值,类似雨java中的反射,而且私有的照样可以设置与获取 2 二 函数 1 retain 给对象引用计数器 + 1 2 release ...
- 24种设计模式--状态模式【State Pattern】
现在城市发展很快,百万级人口的城市一堆一堆的,那其中有两个东西的发明在城市的发展中起到非常重要的作用:一个是汽车,一个呢是...,猜猜看,是什么?是电梯!汽车让城市可以横向扩展,电梯让城市可以纵向延伸 ...
- NPOI_2.1.3-Excel中设置小数、百分比、货币、日期、科学计数法和金额大写
在操作Excel时候一些特殊值的转换是在所难免的,下面就给出转换方法大同小异,代码如下: HSSFWorkbook hssfWorkbook = new HSSFWorkbook(); ISheet ...
- ubuntu fcitx 安装 使用
系统内置的ibus的86五笔,感觉有些老不太好用, 所以安装试用了一下fcitx下的五笔,记录一下安装方法 ,各种搜索... 我的ubuntn版本: #48-Ubuntu SMP Fri Aug 24 ...