Drying
Drying
http://poj.org/problem?id=3104
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 23212 | Accepted: 5842 |
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
设x1为自然晾干的时间,x2为被烘干的时间
a_i=x1+k*x2,mid=x1+x2,可得 x2=(a_i-mid)/(k-1),答案向上取整
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<cmath>
#include<string.h>
#include<stdlib.h>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
typedef long long ll;
const long long MOD=;
#define maxn 100005
using namespace std; ll n,k;
ll a[maxn]; bool Check(ll mid){
ll sum=;
ll tmp,tt;
for(int i=;i<=n;i++){
if(a[i]>mid){
sum+=ll(ceil((a[i]-mid)*1.0/(k-)));
}
}
if(sum<=mid) return true;
return false;
} int main(){
while(~scanf("%lld",&n)){
ll L=,R=,mid;
for(int i=;i<=n;i++){
scanf("%lld",&a[i]);
R=max(R,a[i]);
}
scanf("%lld",&k);
if(k==){
cout<<R<<endl;
continue;
} while(L<=R){
mid=L+R>>;
if(Check(mid)){
R=mid-;
}
else{
L=mid+;
}
}
printf("%lld\n",L);
}
}
Drying的更多相关文章
- POj3104 Drying(二分)
Drying Time Limit: 2000MS Memory Limit: 65536K Description It is very hard to wash and especially to ...
- POJ 3104 Drying(二分答案)
题目链接:http://poj.org/problem?id=3104 ...
- POJ3104 Drying(二分查找)
POJ3104 Drying 这个题由于题目数据比较大(1 ≤ ai ≤ 109),采用贪心的话肯定会超时,自然就会想到用二分. 设C(x)为true时表示所用时间为X时,可以把所有的衣服都烘干或者自 ...
- poj 3104 Drying(二分搜索之最大化最小值)
Description It is very hard to wash and especially to dry clothes in winter. But Jane is a very smar ...
- Drying(贪心)
Drying Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11512 Accepted: 2977 Descripti ...
- Drying poj3104(二分)
Drying Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7916 Accepted: 2006 Descriptio ...
- Drying POJ - 3104
It is very hard to wash and especially to dry clothes in winter. But Jane is a very smart girl. She ...
- POJ3104 Drying 2017-05-09 23:33 41人阅读 评论(0) 收藏
Drying Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 15604 Accepted: 3976 Descripti ...
- poj 3104 Drying(二分查找)
题目链接:http://poj.org/problem?id=3104 Drying Time Limit: 2000MS Memory Limit: 65536K Total Submissio ...
随机推荐
- wordpress模板里加keywords和description
刚才我说了,wp会弄的话,功能是很强大的,插件很多,基本上你能想到的功能,插件都开发好了的.现在就来说说这个keywords和description的问题.我在网上找了些资料,总结一下,如果有引用到的 ...
- scrapy 抓取拉勾网数据
其实很简单,却因为一些小问题,折腾不少时间,简要记录一下,以备后需. >> scrapy startproject lagou >> cd lagou >> scr ...
- @echo 与 echo的区别
@echo运行时 隐藏命令(不在terminal上显示) echo运行时显示命令(在terminal上显示) 同理@cp 与 cp 复制命令 不显示/显示
- SQL的三种连接方式内连接、左连接、外连接
1.内连接 select * from table_a x inner join table_b y on x.a_id = y.b_id 返回两个表关键字x.a_id = y.b_id的交集数据集 ...
- ExtJS 动态组件与组件封装
介绍几个有用的函数: Ext.apply---追加配置选项Ext.reg,----注册xtypeExt.extend--扩展组件||操作({}|| cfg)fireEvent自定义事件机制 --- ...
- 小朋友学Python(2)
本节学习python的第一个程序:输出“Hello World!”.咱们用两种方法实现 方法(一) 进入python环境,直接使用print方法 hello world.png 方法(二) 先编程 ...
- Determining IP information for eth0...failed 错误解决
问题描述:虚拟机使用wget命令上网,执行service network restart后出现如下错误Determining IP information for eth0...failed解决办法: ...
- json 拖拽
1.梳理知识点 1.事件对象 e || event 2.事件对象的属性 鼠标事件对象 : 坐标属性 : clientX clientY pageX pageY offset ...
- Python之模块(一)
模块 在计算机程序的开发过程中,随着程序代码越写越多,在一个文件里代码就会越来越长,越来越不容易维护.为了编写可维护的代码,我们把很多函数分组,分别放到不同的文件里,这样,每个文件包含的代码就相对较少 ...
- 杂: PYTHON上数据储存:推荐h5py
一篇很短的小短文,主要推荐下做科学计算是大量数据的储存问题 最近在做一个CNN的项目,文件夹里有20w张图片要读入并保存到一个data文件(不然每次都读20w文件太麻烦). 折腾了一个下午,发现了一个 ...