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 ...
 
随机推荐
- RDD之七:Spark容错机制
			
引入 一般来说,分布式数据集的容错性有两种方式:数据检查点和记录数据的更新. 面向大规模数据分析,数据检查点操作成本很高,需要通过数据中心的网络连接在机器之间复制庞大的数据集,而网络带宽往往比内存带宽 ...
 - 版本管理工具---svn搭建与使用
			
SVN是Subversion的简称,是一个开放源代码的版本控制系统,相较于RCS.CVS,它采用了分支管理系统,它的设计目标就是取代CVS.互联网上很多版本控制服务已从CVS迁移到Subversion ...
 - unity3d工程下的data file作用
			
projectData文件夹中的data file: 1. Player settings – globalgamemanagers and globalgamemanagers.assets fil ...
 - python之路之迭代器与生成器
			
一 迭代器 那么在研究迭代器之前首先应该要知道什么是迭代. 迭代:是一个重复的过程,并且每次重复都是建立基于上一次的结果而来的,所以在迭代的过程其实是在不断变化的. 迭代器:就是迭代取值的工具. 那 ...
 - jq上下级元素查找方法
			
1.parent([expr]) 获取指定元素的所有父级元素 2.next([expr]) 获取指定元素的下一个同级元素 3.nextAll([expr]) 获取指定元素后面的所有同级元素 4.and ...
 - display属性详解
			
内容: 1.display介绍 2.display分类 3.块级标签和内联标签 4.inline-block应用 1.display介绍 display:display属性设置元素如何被显示 2.di ...
 - python的动态性和_slot_
			
python是动态语言 1. 动态语言的定义 动态编程语言 是 高级程序设计语言 的一个类别,在计算机科学领域已被广泛应用.它是一类 在运行时可以改变其结构的语言 :例如新的函数.对象.甚至代码可以被 ...
 - leetcode453
			
public class Solution { public int MinMoves(int[] nums) { var list = nums.OrderBy(x => x).ToList( ...
 - Linux命令详解----iostat
			
Linux系统出现了性能问题,一般我们可以通过top.iostat.free.vmstat等命令来查看初步定位问题.在一个以前看到系统监控工具,总在想那些监控工具的代理,如何收集系统性能信息,io性能 ...
 - Sender 转换TButtonItem TCategoryButtons
			
http://codeverge.com/embarcadero.cppbuilder.using/using-sender-to-determine-which/1068317 http://qc. ...