Drying (二分法)
来源:互联网 发布:d3.js官网demo 编辑:程序博客网 时间:2024/06/06 19:41
Drying
Time Limit : 4000/2000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 52 Accepted Submission(s) : 14
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 byk 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.
<b>sample input #1</b>32 3 95<b>sample input #2</b>32 3 65
<b>sample output #1</b>3<b>sample output #2</b>2
题意:
有一些衣服,每件衣服都有一定水量,有一个暖气片,每次可以烘掉k滴水,每件衣服每分钟可自动蒸发一滴水,用暖气片烘干时不掉。问最少可以多长时间烘干所有衣服。
思路:
首先想到二分枚举最小的时间,那么就要找衣服水量比最小时间还要大的衣服,则最短时间是蒸发一段时间然后烘干一段时间,在这里,假设需要x分钟机器,那么自然风干就需要(mid-x)分钟,x和mid需要满足:
k*x+(mid-x)>=a[i];那么每件衣服最小需要x>=(a[i]-mid)/(k-1);
注意当k==1时要特殊处理,所需时间即为水量最大的那个衣服。用cin会超时。
代码:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <string>#include <map>#include <stack>#include <vector>#include <set>#include <queue>#include <iomanip>#define maxn 100005#define mod 1000000007#define INF 0x3f3f3f3f#define exp 1e-6#define pi acos(-1.0)using namespace std;long long int a[maxn],maxx,sum,k;int main(){ //ios::sync_with_stdio(false); int n,i; long long low,high,mid; while(scanf("%d",&n)!=EOF) { memset(a,0,sizeof(a)); maxx=0; for(i=0;i<n;i++){ scanf("%lld",&a[i]); if(a[i]>maxx) maxx=a[i]; } scanf("%d",&k); if(k==1) {printf("%lld\n",maxx); continue;} low=1,high=maxx; long long res=0; while(high>=low) { mid=(high+low)/2,sum=0; for(i=0;i<n;i++) { if(a[i]>mid){long long s=ceil((a[i]-mid)*1.0/(k-1));sum+=s;} } if(sum<=mid) { res=mid; high=mid-1; } else low=mid+1; } printf("%lld\n",res); } return 0;}
- Drying (二分法)
- (二分法)【POJ-3104】Drying
- 二分法 POJ-3104 Drying
- poj3104 Drying(二分)
- POJ: Drying(二分)
- Drying--(二分)
- Drying (二分)
- Drying
- Drying
- Drying
- Drying
- POJ3104 Drying(二分答案)
- POJ 3104 Drying(二分)
- poj 3104 Drying(二分)
- POJ 3104 Drying (二分)
- POJ - 3104 Drying (二分搜索)
- POJ 3104 Drying (二分搜索)
- POJ 3104 Drying(最大化最小值)
- ssm分布式架构电商项目(五)
- 二幂拆分问题
- jdk源码分析--了解class文件
- NYOJ 【108】士兵杀敌 一 (线段树 + 模板题)
- STM32在IAR和MDK中使用printf进行串口打印的实现方法
- Drying (二分法)
- python网络爬虫与信息采取之解析网页(二)---BeautifulSoup库的find()和find_all()
- 递归简论
- JAVA深入研究——Method的Invoke方法。
- poj 2065 SETI(高斯消元)
- 循环队列
- 聚类方法之k-mean算法
- hpuoj【1410】QAQ & 火星情报局【数学】
- Django编写中间件实现url自定义过滤