传送门

表示又是神题一道

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

Sample Output

sample output #1
3 sample 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

 #include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<string> #define N 100005
#define M 10
#define mod 1000000007
//#define p 10000007
#define mod2 1000000000
#define ll long long
#define LL long long
#define eps 1e-9
//#define inf 0x3fffffffff
#define maxi(a,b) (a)>(b)? (a) : (b)
#define mini(a,b) (a)<(b)? (a) : (b) using namespace std; int n;
ll ans;
ll a[N];
ll k; void ini()
{
ans=;
int i;
for(i=;i<=n;i++){
scanf("%I64d",&a[i]);
}
scanf("%I64d",&k);
sort(a+,a++n);
} int ok(ll m)
{
int i;
ll le=m;
ll re;
for(i=;i<=n;i++){
re=a[i]-m;
if(re<=) continue;
le-=(re+k-)/(k-);
}
if(le>=) return ;
return ;
} void solve()
{
ll l=;
ll r=a[n];
ll m;
//printf(" %d\n",a[1]);
if(k==){
ans=a[n];return;
}
while(l<r)
{
m=l+(r-l)/;
if(ok(m)==){
r=m;
}
else{
l=m+;
}
}
ans=l;
} void out()
{
printf("%I64d\n",ans);
} int main()
{
// freopen("data.in","r",stdin);
//freopen("data.out","w",stdout);
//scanf("%d",&T);
//for(int ccnt=1;ccnt<=T;ccnt++)
//while(T--)
while(scanf("%d",&n)!=EOF)
{
ini();
solve();
out();
} return ;
}

POJ 3104 Drying [二分 有坑点 好题]的更多相关文章

  1. POJ 3104 Drying(二分答案)

    题目链接:http://poj.org/problem?id=3104                                                                  ...

  2. POJ 3104 Drying 二分

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

  3. POJ 3104 Drying (二分+精度)

    题目链接:click here~~ [题目大意]: 题意:有一些衣服,每件衣服有一定水量,有一个烘干机,每次能够烘一件衣服,每分钟能够烘掉k单位水. 每件衣服没分钟能够自己主动蒸发掉一单位水, 用烘干 ...

  4. POJ 3104 Drying(二分答案)

    [题目链接] http://poj.org/problem?id=3104 [题目大意] 给出n件需要干燥的衣服,烘干机能够每秒干燥k水分, 不在烘干的衣服本身每秒能干燥1水分 求出最少需要干燥的时间 ...

  5. poj 3104 Drying(二分查找)

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

  6. POJ 3104 Drying(二分

    Drying Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 22163   Accepted: 5611 Descripti ...

  7. POJ 3104 Drying (经典)【二分答案】

    <题目链接> 题目大意: 有一些衣服,每件衣服有一定水量,有一个烘干机,每次可以烘一件衣服,每分钟可以烘掉k滴水.每件衣服没分钟可以自动蒸发掉一滴水,用烘干机烘衣服时不蒸发.问最少需要多少 ...

  8. poj 3104 Drying(二分搜索之最大化最小值)

    Description It is very hard to wash and especially to dry clothes in winter. But Jane is a very smar ...

  9. poj 3104 dring 二分

    Drying Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7684   Accepted: 1967 Descriptio ...

随机推荐

  1. 爬虫_python3_urllib

    urlib库为python3的HTTP内置请求库 urilib的四个模块: urllib.request:用于获取网页的响应内容 urllib.error:异常处理模块,用于处理异常的模块 urlli ...

  2. 测试框架 Mocha 实例教程(转载:来自阮一峰的一篇文章)

    Mocha(发音"摩卡")诞生于2011年,是现在最流行的JavaScript测试框架之一,在浏览器和Node环境都可以使用. 所谓"测试框架",就是运行测试的 ...

  3. python之dic {字典}(重要指数*****)

    1. 什么是字典 {'name': '汪峰', 'age': 18} '键':'值' 别的语言键值对数据 键: 必须是可哈希(不可变的数据类型),并且是唯一的 值: 任意 可以保存任意类型的数据 字典 ...

  4. [php扩展] php安装扩展注意事项

    添加扩展的时候注意此3项 用的编译器版本:VC11... 安装的php版本:x86/x64 是否线程安全:enabled / disabled

  5. Python2.7 在使用BSTestRunner.py时报错TypeError: unicode argument expected, got 'str'

    python3往这个库中加入了一些新的内容,使得该库在Python2.7中报错. 解决方法是将导入语句 from io import StringIO as StringIO 更换为: from io ...

  6. 牛客网暑期ACM多校训练营(第五场) E room(最小费用最大流 , 最小权二分图匹配模板)

    链接: https://www.nowcoder.com/acm/contest/143/E 题意: 给定n个宿舍的新安排, 每个宿舍都有4个人, 问要至少有多少个人换位才能变成新安排. 可以建一个二 ...

  7. 在oracle中怎么通过字段名查询其所在的表

    ora = //连接描述符名:ora (description = //描述 (address = //网络地址之一 (protocol = tcp) //网络协议(tcp表示TCP/IP协议) (h ...

  8. 织梦dedecms自定义表单设置必填项

    1. 用php验证 在plus/diy.php的第 40行下加 //增加必填字段判断 if($required!=''){ if(preg_match('/,/', $required)) { $re ...

  9. 【06】前端需要注意哪些SEO

    [06]前端需要注意哪些SEO 01,合理的title,description,keywords. 02,语义化的HTML代码.好处,让搜索引擎更好搜索. 03,重要的HTML内容放前面. 04,重要 ...

  10. cf950f Curfew

    神贪心--写了一个晚上加一个早上. 先考虑只有一个宿管的情况. 首先,如果这个宿舍人多了,多余的人就跑到下一个宿舍.(如果这是最后一个宿舍的话,多的就躺床底下) 如果这个宿舍人少了,但是能从别的宿舍调 ...