题目链接:http://poj.org/problem?id=3104
Drying
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 9440   Accepted: 2407

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
5sample input #2
3
2 3 6
5

Sample Output

sample output #1
3sample output #2
2
题目大意:有n件衣服,每件衣服有一定的水量,使衣服干有两种方法:1、水分蒸发,每分钟蒸发掉一滴水 2、用烘干机烘干,每分钟烘干掉k滴水。题目要输出的是是所有衣服变干的最小时间。

详见代码。
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cmath>
 4
 5 using namespace std;
 6
 7 #define ll long long
 8
 9 int main ()
10 {
11     int n;
12     ll a[100000+10];
13     ll tmax;
14     while (~scanf("%d",&n))
15     {
16         tmax=0;
17         for (int i=0; i<n; i++)
18         {
19             scanf("%lld",&a[i]);
20             if (a[i]>tmax)
21                 tmax=a[i];
22         }
23         ll k;
24         scanf("%lld",&k);
25         if (k==1)
26         {
27             printf ("%lld",tmax);
28             continue;
29         }
30         ll l=1,r=tmax,mid,ans=0;
31         while (r>=l)
32         {
33             ll sum=0;
34             mid=(l+r)/2;
35             for (int i=0;i<n;i++)
36             {
37                 if(a[i]>mid)
38                 {
39                     ll s=ceil((a[i]-mid)*1.0/(k-1));
40                     sum+=s;
41                 }
42             }
43             if (sum>mid)
44                 l=mid+1;
45             else
46                 r=mid-1,ans=mid;
47         }
48         printf ("%lld\n",ans);
49     }
50     return 0;
51 }

 

转载于:https://www.cnblogs.com/qq-star/p/4259173.html

poj 3104 Drying(二分查找)相关推荐

  1. POJ 3104 Drying 二分

    http://poj.org/problem?id=3104 题目大意: 有n件衣服,每件有ai的水,自然风干每分钟少1,而烘干每分钟少k.求全部弄干的最短时间. 思路: 注意烘干时候没有自然风干. ...

  2. POJ 3104 Drying [二分 有坑点 好题]

    传送门 表示又是神题一道 Drying Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9327   Accepted: 23 ...

  3. POJ 3104 Drying【二分搜索】最大化最小值问题

    题意 有N件衣服,每件衣服的函数量为ai,每分钟可以自然脱水1单位:有一个脱水机,每次只能用于一件衣服,每分钟脱水K单位,脱水时,不自然风干,求所有衣服全部脱水的最短时间 分析 二分查找最短时间,下界 ...

  4. POJ 3104(二分算法,难难难)

    背景 最让HSQ学长头疼的就是洗衣服了.洗完之后,每件衣服都有一定单位水分,在不使用烘干器的情况下,每件衣服每分钟自然流失1个单位水分,但如果使用了烘干机则每分钟流失K个单位水分.令人遗憾是HSQ所在 ...

  5. poj 3104 Drying

    晾衣服:n件衣服各含a_i水分,自然干一分钟一单位,放烘干机一分钟k单位,求最短时间. 1.题目中说了一分钟内只能放一件衣服进烘干机,,我这里想的是一分钟内干了后,拿出来再放别的.(额..更节约..) ...

  6. Drying POJ - 3104 二分

    Drying    POJ - 3104  二分      http://poj.org/problem?id=3104 二分查找作用之一:查找结果,逆向求解. 最让HSQ学长头疼的就是洗衣服了.洗完 ...

  7. POJ 2785 有多少种4个数相加等于0的方案(二分查找 or hash)

    文章目录 1.二分查找法 1.1 思路: 1.2 AC代码 2.hash查找法 2.1 思路: 2.2 Wrong Answer 代码 2.3 Time Limit Exceeded 代码 2.4 偷 ...

  8. POJ 1064 分割线缆(二分查找)

    题目链接:http://poj.org/problem?id=1064 题目大意:多根电缆切成指定段数(每段相同长度),求每段线缆的最大长度(精确到0.01) 这题精度控制是难点,方法很简单,二分查找 ...

  9. [POJ 2503] Babelfish【二分查找】

    题目大意 给你一个词典,每行有两个字符串x,y,表示y翻译成x. 一行空行隔开. 给你一些单词y,问你翻译后的x,如果词典里没有,那么就输出"eh" 解题报告 C++调map,还可 ...

最新文章

  1. GICP:基于体素泛化ICP方式的准确快速点云配准方法
  2. 智能车竞赛技术报告 | 全向行进组 - 沈阳工业大学 - 找不到北队
  3. JS流程控制语句 二选一 (if...else语句) 语法: if(条件) { 条件成立时执行的代码} else {条件不成立时执行的代码}...
  4. 词法分析器和lex工具基本学习
  5. CSS之定位布局(position,relative定位布局技巧)
  6. 深度之眼课程打卡-python入门05
  7. 单向链表的简单Java实现-sunziren
  8. iservice封装有哪些方法_对WebService的一些封装技巧总结
  9. 使DIV水平和垂直居中
  10. 变量声明提升和函数声明提升
  11. c语言跑马灯循环三次停止,跑马灯代码 连续不间断的跑马灯的代码(js)
  12. 安卓手机利用DroidCam当电脑摄像头使用方法
  13. 内联css加伪元素,使用CSS:前和:后内联CSS伪元素?(Using CSS :before and :after p
  14. 自动控制系统中的典型环节
  15. ue转换文件格式linux,关于windows与unix之间文件格式转换问题。UE编辑器中(CR/LF)问题...
  16. 数论——Baby Step Giant Step大步小步算法
  17. buildroot_buildroot-我对多平台发行版创作的经验
  18. 万马股份旗下万马爱充遭通报下架:违规收集个人信息,未及时整改
  19. Python | 用Python画个美队盾牌送给你
  20. C++ 什么是继承和派生

热门文章

  1. (新鲜出炉)二本,两年经验,阿里P6面经
  2. Python面向对象(三)
  3. 以外包角度谈美术制程 Studio Voltz联合创始人开发经验
  4. pmp最近5题(2022年3月23日)
  5. MySQL中myisam和innodb的主键索引有什么区别?
  6. MySQL数据库MVCC多版本并发控制简介
  7. 程序员的自我修养,好文
  8. spring-boot-autoconfigure-xx.jar核心注解
  9. springboot官网-pom.xml文件
  10. Linux漏洞CVE整理