POJ3104 Drying
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 13703 | Accepted: 3527 |
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
这是一道潮湿的题……
二分测试答案,看用这个时间能不能把所有衣服都烘干。
/*by SilverN*/
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
const int mxn=;
int n;long long k;
long long a[mxn];
long long ans=;
long long calc(long long x){
int i,j;
long long cnt=;
for(i=;i<=n;i++){
if(a[i]>x){
long long xx = ceil((a[i]-x) * 1.0 / (k - ) );
cnt+=xx;
}
}
return cnt;
}
int main(){
scanf("%d",&n);
int i,j;
long long mxt=;
for(i=;i<=n;i++)
scanf("%lld",&a[i]),mxt=max(mxt,a[i]);
scanf("%lld",&k);
if(k==){
printf("%lld\n",mxt);
return ;
}
ans=;
long long l=,r=mxt;
while(l<=r){
long long mid=(l+r)/;
long long res=calc(mid);
if(res<=mid){
ans=mid;
r=mid-;
}
else l=mid+;
}
printf("%lld\n",ans);
return ;
}
POJ3104 Drying的更多相关文章
- POJ3104 Drying(二分查找)
POJ3104 Drying 这个题由于题目数据比较大(1 ≤ ai ≤ 109),采用贪心的话肯定会超时,自然就会想到用二分. 设C(x)为true时表示所用时间为X时,可以把所有的衣服都烘干或者自 ...
- POj3104 Drying(二分)
Drying Time Limit: 2000MS Memory Limit: 65536K Description It is very hard to wash and especially to ...
- poj3104 Drying(二分最大化最小值 好题)
https://vjudge.net/problem/POJ-3104 一开始思路不对,一直在想怎么贪心,或者套优先队列.. 其实是用二分法.感觉二分法求最值很常用啊,稍微有点思路的二分就是先推出公式 ...
- POJ3104 Drying 2017-05-09 23:33 41人阅读 评论(0) 收藏
Drying Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 15604 Accepted: 3976 Descripti ...
- POJ3104 Drying —— 二分
题目链接:http://poj.org/problem?id=3104 Drying Time Limit: 2000MS Memory Limit: 65536K Total Submissio ...
- POj-3104 Drying 二分+贪心
题目大意:有n件湿的衣服,每件衣服都有相应的湿度,每分钟每件衣服的湿度减1(除了在烘干机里的衣服),现在有一个烘干机,烘干机一分钟可以让一件衣服的湿度降低k,问至少要花多少分钟才能使每件衣服的湿度为0 ...
- Drying poj3104(二分)
Drying Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7916 Accepted: 2006 Descriptio ...
- Drying [POJ3104] [二分答案]
背景 每件衣服都有一定单位水分,在不适用烘干器的情况下,每件衣服每分钟自然流失1个单位水分,但如果使用了烘干机则每分钟流失K个单位水分,但是遗憾是只有1台烘干机,每台烘干机同时只能烘干1件衣服,请问要 ...
- 【POJ - 3104 】Drying(二分)
Drying 直接上中文 Descriptions 每件衣服都有一定单位水分,在不使用烘干器的情况下,每件衣服每分钟自然流失1个单位水分,但如果使用了烘干机则每分钟流失K个单位水分,但是遗憾是只有1台 ...
随机推荐
- Android驱动开发读书笔记六
第六章 Linux 驱动的工作和访问方式是 Linux 的亮点之一,Linux 系统将每一个驱动都映射成一个文件.这些文件称为设备文件或驱动文件,都保存在/dev目录中,由于大多数Linux驱动都有与 ...
- 1048: [HAOI2007]分割矩阵
Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1184 Solved: 863[Submit][Status][Discuss] Descripti ...
- 4- vue django restful framework 打造生鲜超市 -restful api 与前端源码介绍
4- vue django restful framework 打造生鲜超市 -restful api 与前端源码介绍 天涯明月笙 关注 2018.02.20 19:23* 字数 762 阅读 135 ...
- 第七篇:suds.TypeNotFound: Type not found: '(string, http://schemas.xmlsoap.org/soap/encoding/, )'
想要用Python的suds模块调用webservice地址做自动测试,但是找了很多方法都失败了,最终找到另外一个模块可以作为客户端访问服务器地址. 1.针对非安全的http from zeep im ...
- 20190103(GIL,池,阻塞,同步异步)
GIL锁 什么是GIL GIL全局解释器锁,是防止多个线程在同一时间同时执行的.CPython解释器特有的一种互斥锁. 每一个py文件都会有自己的解释器,也就是说不同py文件的GIL都是独立的, ps ...
- 解决Uva网站打开慢的问题
https://blog.csdn.net/richenyunqi/article/details/80990535
- Xadmin添加用户小组件出错render() got an unexpected keyword argument 'renderer
环境: Python 3.5.6 Django 2.1 Xadmin 原因: render函数在django2.1上有变化 解决方案: 1.在Python终端输入命令help('xadmin') 查看 ...
- TCP/IP网络编程之I/O流分离
分离I/O流 “分离I/O流”是一种常用表达,有I/O工具可以区分二者.无论使用何种办法,都可以认为分离I/O流.我们之前通过两种方法分离I/O流,第一种是TCP/IP网络编程之进程间通信中的“TCP ...
- BMP图片的加载方式:资源 VS 文件
在程序中加载位图有很多方法,各有各的好处.这里简单说一下在资源里和文件里加载的区别. 第一.在资源里加载位图 这种方法就是在工程里的“资源视图”-->“添加资源”-->"Bitm ...
- 使用 SpiritManager 类管理在 XNA 游戏中的精灵(十四)
平方已经开发了一些 Windows Phone 上的一些游戏,算不上什么技术大牛.在这里分享一下经验,仅为了和各位朋友交流经验.平方会逐步将自己编写的类上传到托管项目中,没有什么好名字,就叫 WPXN ...