传送门

表示又是神题一道

Drying
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 9327   Accepted: 2364

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

Source

Northeastern Europe 2005, Northern Subregion

本来想贪心的,结果越写越乱,老老实实二分。。。不过这题有其精妙之处,wa的人先看样例

送点test data给WA的朋友们……

Posted by MIRKING at 2008-07-31 13:39:06 on Problem 3104 and last updated at 2008-07-31 13:40:02


test data:
2
8
9
2
result:6
7
1000000000
1000000000
1000000000
1000000000
1000000000
1000000000
1000000000
2
result:875000000

Re:为什么二分时 枚举的时间l,r,mid不用__int64就wa了

Posted by wangyaoxuan at 2010-10-14 11:30:23 on Problem 3104 In Reply To:为什么二分时 枚举的时间l,r,mid不用__int64就wa了 Posted by:wangyaoxuan at 2010-10-14 11:22:39

表示理解了,因为过程中求得的时间值t会超过int,后来的wa们慢慢体会....

Posted by lgq1205 at 2009-12-03 12:54:33 on Problem 3104


二分枚举时间,判断可行性,然后求解即可.注意判断可行性的过程:1.先把所有衣服的含水量减去T
2.然后把>=(k-1)的拿去烘干,可以理解为烘干时候每分钟掉(k-1)水,这样所有的衣服都每分钟自然干掉1水了。因为每分钟掉一滴水是肯定的了,因此,如果你去烘干它的话,那么它就能再掉多k-1 + 1 == k,这样才是k滴水,然后就是计算总花费时间
3.最后判断总花费时间时候小于T,若小于等于,则可行性,否则不可行.

如果你WA了,看一下是否有变量要设为64位int,如果RE了,看一下除零。。。

Posted by 2745972075 at 2014-07-21 15:47:54 on Problem 3104
 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdlib>
 4 #include<cstdio>
 5 #include<algorithm>
 6 #include<cmath>
 7 #include<queue>
 8 #include<map>
 9 #include<set>
10 #include<stack>
11 #include<string>
12
13 #define N 100005
14 #define M 10
15 #define mod 1000000007
16 //#define p 10000007
17 #define mod2 1000000000
18 #define ll long long
19 #define LL long long
20 #define eps 1e-9
21 //#define inf 0x3fffffffff
22 #define maxi(a,b) (a)>(b)? (a) : (b)
23 #define mini(a,b) (a)<(b)? (a) : (b)
24
25 using namespace std;
26
27 int n;
28 ll ans;
29 ll a[N];
30 ll k;
31
32 void ini()
33 {
34     ans=0;
35     int i;
36     for(i=1;i<=n;i++){
37         scanf("%I64d",&a[i]);
38     }
39     scanf("%I64d",&k);
40     sort(a+1,a+1+n);
41 }
42
43 int ok(ll m)
44 {
45     int i;
46     ll le=m;
47     ll re;
48     for(i=1;i<=n;i++){
49         re=a[i]-m;
50         if(re<=0) continue;
51         le-=(re+k-2)/(k-1);
52     }
53     if(le>=0) return 1;
54     return 0;
55 }
56
57 void solve()
58 {
59     ll l=1;
60     ll r=a[n];
61     ll m;
62     //printf(" %d\n",a[1]);
63     if(k==1){
64         ans=a[n];return;
65     }
66     while(l<r)
67     {
68         m=l+(r-l)/2;
69         if(ok(m)==1){
70             r=m;
71         }
72         else{
73             l=m+1;
74         }
75     }
76     ans=l;
77 }
78
79 void out()
80 {
81     printf("%I64d\n",ans);
82 }
83
84 int main()
85 {
86    // freopen("data.in","r",stdin);
87     //freopen("data.out","w",stdout);
88     //scanf("%d",&T);
89     //for(int ccnt=1;ccnt<=T;ccnt++)
90     //while(T--)
91     while(scanf("%d",&n)!=EOF)
92     {
93         ini();
94         solve();
95         out();
96     }
97
98     return 0;
99 }

转载于:https://www.cnblogs.com/njczy2010/p/4211555.html

POJ 3104 Drying [二分 有坑点 好题]相关推荐

  1. POJ 3104 Drying 二分

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

  2. poj 3104 Drying(二分查找)

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

  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 2049(二分+spfa判负环)

    poj 2049(二分+spfa判负环) 给你一堆字符串,若字符串x的后两个字符和y的前两个字符相连,那么x可向y连边.问字符串环的平均最小值是多少.1 ≤ n ≤ 100000,有多组数据. 首先根 ...

  8. A - Expanding Rods POJ - 1905(二分)

    A - Expanding Rods POJ - 1905(二分) 题目 Problem Description When a thin rod of length L is heated n deg ...

  9. Divide and conquer:Drying(POJ 3104)

    烘干衣服 题目大意:主人公有一个烘干机,但是一次只能烘干一件衣服,每分钟失水k个单位的水量,自然烘干每分钟失水1个单位的水量(在烘干机不算自然烘干的那一个单位的水量),问你最少需要多长时间烘干衣服? ...

最新文章

  1. python申请内存函数_Python Ctypes c函数的内存分配
  2. 在线抓娃娃爆火之后,新玩家入局还有希望吗?
  3. asiHttpRequst 学习地址
  4. aws dynamodb_带有AWS DynamoDB的React式Spring Webflux
  5. 安装mysql需要配置什么软件_软件配置篇-MySQL下载及安装
  6. python学习手册-Python学习手册
  7. atitit.薄伽梵歌overview  attilax 读后感
  8. 计算机wind10切换桌面wind7系统,win10一键切回win7桌面方法_Win10桌面切换成Win7界面的方法...
  9. 商务与经济统计(13版,Python)笔记 01-02章
  10. 复杂网络作业四:第三题——随机图、小世界网络和真实网络的度分布
  11. 数模笔记(四):插值与拟合1.0
  12. 基于Arduino的吉他调音器
  13. UE4_虚幻引擎4多人联机基础知识和客户端服务器通信机制详解
  14. NC18979 毒瘤xor
  15. win7系统ftp服务器密码修改,win7 ftp服务器密码
  16. 2019113_房价预测
  17. 山寨“苹果皮”上市或涉嫌侵权iPhon
  18. 深入理解Spark RDD——RDD实现的初次分析
  19. Ubuntu下键盘输入错乱问题
  20. 考研计算机科学与技术属于,考研报名计算机科学与技术属于哪一类

热门文章

  1. 合泰单片机数码管c语言,合泰单片机定时器数码管显示
  2. python3入门基础语法总结_Python基础语法总结
  3. 关于主机的思维导图_读《思维导图》系列丛书----我用思维导图做什么?
  4. 返回包禁止返回server_kubernetes部署metrics-server
  5. python测试程序的qps和响应时间代码_python性能测试,请求QPS测试
  6. 创维oled工厂模式abd_创维电视五大新品释放创新社交属性,让新年「大有可玩」...
  7. linux超级密码,找回Linux超级用户root密码
  8. c++大作业迷宫游戏 规定时间内完成_孩子写作业慢的7种原因及其解决对策
  9. linkedlist java 实现_Java LinkedList 实现原理
  10. 零基础学前端之css3高级特效