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 (存多条边示例)
题目背景 在艾泽拉斯大陆上有一位名叫歪嘴哦的神奇术士,他是部落的中坚力量 有一天他醒来后发现自己居然到了联盟的主城暴风城 在被众多联盟的士兵攻击后,他决定逃回自己的家乡奥格瑞玛 题目描述 在艾泽拉斯, ...
随机推荐
- MVC3中使用AuthorizeAttribute特性来完成登陆权限的验证
以前判断用户是否登录,判断用户Session是否为空,一般会在这个页面写使用: if (HttpContext.Session.IsNewSession) { //todo Login } 每个需要验 ...
- 有理数类 Java BigInteger实现
import java.math.BigInteger; public class Rational extends Number implements Comparable { private Bi ...
- Ajax异步的回调函数执行了多遍
问题: 在做下拉滚动加载时(类似于qq空间下拉加载),数据向下滚动一次,就会加载一次,即append一下,跟踪js后,发现回调函数执行了多次,导致append将上次的append结果append上了, ...
- tomcat优化系列:修改运行内存
1.对于安装版的TOMCAT: 进入TOMCAT的安装目录下的bin目录,双击tomcat6w.exe.点击Java选项卡,可设置初始化内存,最大内存,线程的内存大小. 初始化内存:如果机器的内存足够 ...
- C# Unix时间戳转换为时间
在做一些接口的时候,比如返回数据中有一个时间的属性,它的值是使用Unix时间戳表示的,当我们处理它(保存到本地或者格式化前台展示)时需要转换成日期时间,在此就需要根据时间戳转换为日期时间 (注:Uni ...
- easyui-helloworld
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 01_JavaMail_05_创建邮件工具类MailUtils等方便发送邮件
[工程截图] [代码实现] [Mail.java] package com.Higgin.Utils; import java.util.ArrayList; import java.util.Lis ...
- [CUDA] ubuntu14.04+cuda7.5下安装cudnn7.0
cuda:7.5 cudnn:cudnn-7.0-linux-x64-v4.0-prod.tgz cudnn样例:cuDNN v4 Code Samples 1. 解压 tar -zxvf cudnn ...
- 关于Hibernate框架的面试题
1.Hibernate的工作原理及为什么要用? 原理: 1读取并解析配置文件 2.读取并解析映射信息,创建SessionFactory 3.打开Session 4.创建事务Transation 5.持 ...
- React组件一
<div id='test'></div> <script type='text/babel'> var Zu=React.createClass({ return ...