POJ 3104 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
本来想贪心的,结果越写越乱,老老实实二分。。。不过这题有其精妙之处,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 [二分 有坑点 好题]的更多相关文章
- 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 (二分+精度)
题目链接:click here~~ [题目大意]: 题意:有一些衣服,每件衣服有一定水量,有一个烘干机,每次能够烘一件衣服,每分钟能够烘掉k单位水. 每件衣服没分钟能够自己主动蒸发掉一单位水, 用烘干 ...
- POJ 3104 Drying(二分答案)
[题目链接] http://poj.org/problem?id=3104 [题目大意] 给出n件需要干燥的衣服,烘干机能够每秒干燥k水分, 不在烘干的衣服本身每秒能干燥1水分 求出最少需要干燥的时间 ...
- poj 3104 Drying(二分查找)
题目链接:http://poj.org/problem?id=3104 Drying Time Limit: 2000MS Memory Limit: 65536K Total Submissio ...
- POJ 3104 Drying(二分
Drying Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 22163 Accepted: 5611 Descripti ...
- POJ 3104 Drying (经典)【二分答案】
<题目链接> 题目大意: 有一些衣服,每件衣服有一定水量,有一个烘干机,每次可以烘一件衣服,每分钟可以烘掉k滴水.每件衣服没分钟可以自动蒸发掉一滴水,用烘干机烘衣服时不蒸发.问最少需要多少 ...
- poj 3104 Drying(二分搜索之最大化最小值)
Description It is very hard to wash and especially to dry clothes in winter. But Jane is a very smar ...
- poj 3104 dring 二分
Drying Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7684 Accepted: 1967 Descriptio ...
随机推荐
- jQuery筛选器及练习
jQuery初识 jQuery是什么? jQuery是一个兼容多浏览器的JavaScript库. jQuery能极大地简化JavaScript编程,它的宗旨就是:"Write less, ...
- UEditor1.4.3的实例程序
官网:http://ueditor.baidu.com/website/ 配置下就可以使用 (1)下载,解压后文件结构如下: (2)将整个文件夹改名ueditor后复制到WebRoot目录下: (3) ...
- 个人总结NDIS中NDIS_PACKET,NDIS_BUFFER的关系
// // NDIS_PACKET结构的定义 // typedef struct _NDIS_PACKET { NDIS_PACKET_PRIVATE Private; //这个其实是一个链表结构,P ...
- ios之coredata(二)
上面一篇文章介绍了coredata的有关基本概念,由于大部分是参考别人文章中的内容,所以感觉有点虚,而且估计也是比较难以理解,下面这篇文章通俗一点说说学习coredata后的一些理解,然后给出一个简单 ...
- POJ-2251-地下城
这题是一道简单的广搜题目,读入的时候,需要注意,如果是用scanf读入的话,就直接读取每行的字符串,不然的话,行尾的回车,也会被当成字符读入,这样的话,每次读取的数目就会小于我们想要的数目,因为每次把 ...
- [BZOJ] 2662: [BeiJing wc2012]冻结
https://www.lydsy.com/JudgeOnline/problem.php?id=2662 第一次写分层图(捂脸) 一开始真的naive地建图了,T到飞起.. 可以省下建图的空间,直接 ...
- [LUOGU] P1063 能量项链
题目描述 在Mars星球上,每个Mars人都随身佩带着一串能量项链.在项链上有N颗能量珠.能量珠是一颗有头标记与尾标记的珠子,这些标记对应着某个正整数.并且,对于相邻的两颗珠子,前一颗珠子的尾标记一定 ...
- [LUOGU] P2759 奇怪的函数
题目描述 使得 x^x x x 达到或超过 n 位数字的最小正整数 x 是多少? 输入输出格式 输入格式: 一个正整数 n 输出格式: 使得 x^xx x 达到 n 位数字的最小正整数 x 输入输出样 ...
- python 购物车小程序(列表、循环、条件语句)
goods = [ ['iphone6s', 5800], ['mac book', 9000], ['coffee', 32], ['python book', 80], ['bicyle', 15 ...
- BFS:UVa201-Squares
Squares A children's board game consists of a square array of dots that contains lines connecting so ...