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

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.

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 题意: 有n件湿衣服, 现在要把它们烘干(或自然风干), 已知烘干机的效率是每分钟 k 的水分。 自然风干是每分钟 1 的水分。
求最短的烘干时间(整数)。
分析: 0 时间内一定不能烘干。 MAX(水分最多的自然风干用时) 的时间一定能烘干(因为不用烘干,也能风干) 假设 用时 mid 则:
如果a[i]<=mid自然风干就行啦, 如果 a[i]>mid 就要用到烘干机, 假设用 x分钟的烘干机, 则需要满足a[i]-k*x<=mid-x
得出x = ceil(a[i]-mid)/(k-1) 【其中ceil是向上取整的函数,包含在cmath头文件里】 得出各个衣服所需要的烘干时间x,
然后加起来等于res 如果res<mid 则减小mid(用二分法), 否则增大mid。直到求出正确答案。细节详见代码! 二分答案方法的要求:
《1》 能够确定出答案所在的范围。
《2》 答案有在范围内的单调性
《3》 答案是整数(或有一定的精度要求), 而不是十分精确的实数。
二分答案的时间复杂度是logN。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std; int n, a[], k;
bool check(int mid)
{
long long res = ;
for(int i=; i<n; i++)
{
if(a[i]>mid)
{
res+=(int)ceil((double)(a[i]-mid)/(k-));
}
}
return res<=mid;
} int main()
{
while(scanf("%d", &n)!=EOF)
{
int Max=;
for(int i=; i<n; i++)
{
scanf("%d", &a[i]);
if(a[i]>Max) Max=a[i];
}
scanf("%d", &k);
if(k==)
{
printf("%d\n", Max);
continue;
}
int left = , right = Max, mid;
while(right>=left)
{
mid = (right+left)>>;
if(check(mid)) right = mid-;
else left = mid+;
}
printf("%d\n", left);
}
return ;
}
 

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 (二分+精度)

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

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

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

  5. POJ 3122 Pie 二分答案

    题意:给你n个派,每个派都是高为一的圆柱体,把它等分成f份,每份的最大体积是多少. 思路: 明显的二分答案题-- 注意π的取值- 3.14159265359 这样才能AC,,, //By Sirius ...

  6. POJ 3104 Drying(二分答案)

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

  7. poj 3104 Drying(二分查找)

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

  8. POJ 3104 Drying(二分

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

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

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

随机推荐

  1. myeclipse启动报错 no java virtual machine。。。

    如果环境变量里已经配置了JAVA_HOME,但是在启动的时候还会提示下面的信息:   A Java Runtime Environment (JRE) or Java Development Kit ...

  2. init_MUTEX 与 sema_init 函数【转】

    转自:http://blog.chinaunix.net/uid-7332782-id-3211627.html 在编译Linux设备驱动程序学习(1)-字符设备驱动程序中scull.c程序时,报错: ...

  3. oracle 数据泵 每天自动备份

    @echo off echo 删除10天前的备分文件和日志 forfiles /p "e:\app\back" /m *.dmp /d -5 /c "cmd /c del ...

  4. shell获取目录下最新的文件,文件是以日期命名

    如果你为每个文件按日期命名的格式都一致的话,那么 "ls -l" 命令列出的文件列表就是默认按文件名称(日期先后)排序的.那么最后一个就是最新的,文件名可以用以下方式获取.file ...

  5. inupt textarea提示文字(点击消失,不输入恢复)

    <input name="textfield" type="text"  maxlength="20" value="请输入 ...

  6. 怎么使用Docker搭建PHP开发环境呢?

    在Docker流行之前,要搭建开发环境通常有两种选择:一种是使用wamp.xampp.mamp等集成开发环境安装包,另外一种就是使用普通虚拟机来安装linux服务器,然后通过下载一键安装包(如:lnm ...

  7. 提高PHP性能的实用方法+40个技巧优化您的PHP代码

    1.用单引号代替双引号来包含字符串,这样做会更快一些.因为PHP会在双引号包围的字符串中搜寻变量,单引号则不会,注意:只有echo能这么做,它是一种可以把多个字符串当作参数的"函数" ...

  8. [c++][语言语法]函数模板和模板函数 及参数类型的运行时判断

    参考:http://blog.csdn.net/beyondhaven/article/details/4204345 参考:http://blog.csdn.net/joeblackzqq/arti ...

  9. DailyReport自动保存工具

    PS:自己初学C#,SharePoint时做的一个小tool. Friday, November 28, 2014 ​这个tool编译出来以后可以把部门的daily report保存到本地,数据库,和 ...

  10. Get与Post的一些总结

    1.GET请求的数据会附在URL之后,POST把提交的数据则放置在是HTTP包的包体中. 2."GET方式提交的数据最多只能是1024字节这句话是错误的 URL不存在参数上限的问题,HTTP ...