传送门

表示又是神题一道

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. eclipse 的project explorer问题,这个怎样把localFileSystem去掉,

    这个非常简单 把勾去掉就可以了

  2. win10搭建Java环境

    一.下载地址    jdk和jre官方网址:http://www.oracle.com/technetwork/java/javase/downloads/index.html 根据你的系统选择你需要 ...

  3. tcpdump简单使用

    1.使用wincap将文件放入系统任意路径, 2.进入系统,赋文件可执行权限, 3.输入命令:./tcpdump -i eth0 -s 0 -w xxx.pcap 4.进行数据交互 5.退出程序运行, ...

  4. syslog(),closelog()与openlog()--日志操作函数 (1)

    文章出处:http://blog.csdn.net/xx77009833/archive/2010/07/30/5776383.aspx 为了满足某些目的,进行日志记录是很有必要的. 在典型的 LIN ...

  5. Luogu P3727 曼哈顿计划E 点分治+hash

    题目: P3727曼哈顿计划E 分析: 大长题面容易给人一种不可做的错觉,但是这题考的知识点都是我们熟悉的. 稍加分析我们可以得到,我们可以把每个点当成一个单独的游戏,如果k=1,就是简单的nim游戏 ...

  6. 八:SQL之DQL数据查询语言单表操作

    前言: DQL数据库查询语言是我们在开发中最常使用的SQL,这一章总结了单表操作部分的常用查询方式 主要操作有:查询所有字段.查询指定字段.查询指定记录.带IN的关键字查询,范围查询,陪查询.查询空值 ...

  7. Shell中各种括号的作用

    一.小括号,圆括号() 1.单小括号 () ① 命令组.括号中的命令将会新开一个子shell顺序执行,所以括号中的变量不能够被脚本余下的部分使用.括号中多个命令之间用分号隔开,最后一个命令可以没有分号 ...

  8. file结构体

    struct file结构体定义在include/linux/fs.h中定义.文件结构体代表一个打开的文件,系统中的每个打开的文件在内核空间都有一个关联的 struct file.它由内核在打开文件时 ...

  9. spring mvc3 配置<mvc:resources/> @Controller失效

    因为配置了:<mvc:resources  location=" "  mapping=""  /> ,@Controller失效访问404 这里还 ...

  10. CentOS下配置LVM和RAID

    1.CentOS配置LVM http://www.cnblogs.com/mchina/p/linux-centos-logical-volume-manager-lvm.html http://ww ...