博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 3104 Drying(二分答案)
阅读量:4987 次
发布时间:2019-06-12

本文共 2406 字,大约阅读时间需要 8 分钟。

                  
                                                                                   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 #132 3 95sample input #232 3 65

Sample Output

sample output #13sample output #22 题意: 有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
#include
#include
#include
#include
using namespace std;int n, a[100005], k;bool check(int mid){ long long res = 0; for(int i=0; i
mid) { res+=(int)ceil((double)(a[i]-mid)/(k-1)); } } return res<=mid;} int main(){ while(scanf("%d", &n)!=EOF) { int Max=0; for(int i=0; i
Max) Max=a[i]; } scanf("%d", &k); if(k==1) { printf("%d\n", Max); continue; } int left = 0, right = Max, mid; while(right>=left) { mid = (right+left)>>1; if(check(mid)) right = mid-1; else left = mid+1; } printf("%d\n", left); } return 0;}

 

 

转载于:https://www.cnblogs.com/acm1314/p/4787991.html

你可能感兴趣的文章
0x51 线性DP
查看>>
mongo数据库的增删改查
查看>>
软件工程驻足篇章:第十七周和BugPhobia团队漫长的道别
查看>>
ideal 快捷键
查看>>
【转】shell学习笔记(六)——流程控制之for循环
查看>>
python
查看>>
DedeCms常用内容调用标签实例大全
查看>>
使用soapui调用webservice接口
查看>>
java 线程协作 join()
查看>>
微信群价值塑造方法
查看>>
golang学习笔记15 golang用strings.Split切割字符串
查看>>
jQuery页面滚动图片等元素动态加载实现
查看>>
Html5 iphone - Boot Page
查看>>
Mongodb01 - Mongodb安装与配置
查看>>
深入理解对象的引用
查看>>
starUML破解-version2.8.0已验证
查看>>
selenium实战学习第一课
查看>>
马后炮之12306抢票工具(三) -- 查票(监控)
查看>>
198. House Robber Java Solutions
查看>>
Java_基础篇(杨辉三角)
查看>>