poj 3104 Drying(二分查找)
|
Drying
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 Sample Output sample output #1 |
题目大意:有n件衣服,每件衣服有一定的水量,使衣服干有两种方法:1、水分蒸发,每分钟蒸发掉一滴水 2、用烘干机烘干,每分钟烘干掉k滴水。题目要输出的是是所有衣服变干的最小时间。 详见代码。
#include <iostream>
#include <cstdio>
#include <cmath> using namespace std; #define ll long long int main ()
{
int n;
ll a[+];
ll tmax;
while (~scanf("%d",&n))
{
tmax=;
for (int i=; i<n; i++)
{
scanf("%lld",&a[i]);
if (a[i]>tmax)
tmax=a[i];
}
ll k;
scanf("%lld",&k);
if (k==)
{
printf ("%lld",tmax);
continue;
}
ll l=,r=tmax,mid,ans=;
while (r>=l)
{
ll sum=;
mid=(l+r)/;
for (int i=;i<n;i++)
{
if(a[i]>mid)
{
ll s=ceil((a[i]-mid)*1.0/(k-));
sum+=s;
}
}
if (sum>mid)
l=mid+;
else
r=mid-,ans=mid;
}
printf ("%lld\n",ans);
}
return ;
}
poj 3104 Drying(二分查找)的更多相关文章
- POJ 3104 Drying(二分答案)
题目链接:http://poj.org/problem?id=3104 ...
- POJ 3104 Drying 二分
http://poj.org/problem?id=3104 题目大意: 有n件衣服,每件有ai的水,自然风干每分钟少1,而烘干每分钟少k.求所有弄干的最短时间. 思路: 注意烘干时候没有自然风干. ...
- POJ 3104 Drying [二分 有坑点 好题]
传送门 表示又是神题一道 Drying Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9327 Accepted: 23 ...
- POJ 3104 Drying (二分+精度)
题目链接:click here~~ [题目大意]: 题意:有一些衣服,每件衣服有一定水量,有一个烘干机,每次能够烘一件衣服,每分钟能够烘掉k单位水. 每件衣服没分钟能够自己主动蒸发掉一单位水, 用烘干 ...
- poj 2452(RMQ+二分查找)
题目链接: http://poj.org/problem?id=2452 题意:在区间[1,n]上找到满足 a[i]<a[k]<a[j] (i<=k<=j) 的最大子区间 (j ...
- POJ 3104 Drying(二分答案)
[题目链接] http://poj.org/problem?id=3104 [题目大意] 给出n件需要干燥的衣服,烘干机能够每秒干燥k水分, 不在烘干的衣服本身每秒能干燥1水分 求出最少需要干燥的时间 ...
- POJ 3104 Drying(二分
Drying Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 22163 Accepted: 5611 Descripti ...
- POJ 3104 Drying (经典)【二分答案】
<题目链接> 题目大意: 有一些衣服,每件衣服有一定水量,有一个烘干机,每次可以烘一件衣服,每分钟可以烘掉k滴水.每件衣服没分钟可以自动蒸发掉一滴水,用烘干机烘衣服时不蒸发.问最少需要多少 ...
- poj 3122 (二分查找)
链接:http://poj.org/problem?id=3122 Pie Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1 ...
随机推荐
- 如何彻底解决adb 5037端口被占用
在进行安卓开发的时候是不是经常碰到adb端口被占用的情况? 解决这个问题的方法很简单,只需要设置一个系统环境变量就可以搞定. 设置方法: 增加系统环境变量变量名称:ADNROID_ADB_SERVER ...
- Oracle导数据到SQL server的方法总结
通过oracle10g 访问sql server 2008 导数据步骤 最近在项目中遇到要将Oracle数据库的数据导入到SQL server数据库中,解决办法如下: 一.准备工作 配置Oracle ...
- 请问:在delphi中怎样判断DBgrid中数据是否被修改,以便在退出窗口时加以提示
若DBGrid.DataSource.DateSet为ADOQuery1,这样试一下:if ADOQuery1.Modified then ... procedure TForm1.FormClose ...
- MyBatis的架构设计以及实例分析
MyBatis是目前非常流行的ORM框架,它的功能很强大,然而其实现却比较简单.优雅.本文主要讲述MyBatis的架构设计思路,并且讨论MyBatis的几个核心部件,然后结合一个sel ...
- stm32f407启动文件分析
; Amount of memory (in bytes) allocated for Stack; Tailor this value to your application needs; < ...
- 【bzoj1030】[JSOI2007]文本生成器 AC自动机+dp
题目描述 JSOI交给队员ZYX一个任务,编制一个称之为“文本生成器”的电脑软件:该软件的使用者是一些低幼人群,他们现在使用的是GW文本生成器v6版.该软件可以随机生成一些文章―――总是生成一篇长度固 ...
- select、poll、epoll模型对比
select.poll.epoll模型对比 先说Select: 1.Socket数量限制:该模式可操作的Socket数由FD_SETSIZE决定,内核默认32*32=1024. ...
- 【刷题】BZOJ 3140 [Hnoi2013]消毒
Description 最近在生物实验室工作的小T遇到了大麻烦. 由于实验室最近升级的缘故,他的分格实验皿是一个长方体,其尺寸为abc,a.b.c 均为正整数.为了实验的方便,它被划分为abc个单位立 ...
- 洛谷 P2258 子矩阵 解题报告
P2258 子矩阵 题目描述 给出如下定义: 子矩阵:从一个矩阵当中选取某些行和某些列交叉位置所组成的新矩阵(保持行与列的相对顺序)被称为原矩阵的一个子矩阵. 例如,下面左图中选取第 2 . 4行和第 ...
- Base64 编解码
Base64编码简介 Base64用来将binary的字节序列数据编码成ASCII字符序列构成的文本.其使用的字符包括大小写字母各26个,加上10个数字,和加号“+”,斜杠“/”,一共64个字符.另外 ...