poj 3104 Drying(二分查找)
2015-01-29 11:10
429 查看
题目链接:http://poj.org/problem?id=3104
Drying
Itisveryhardtowashandespeciallytodryclothesinwinter.ButJaneisaverysmartgirl.Sheisnotafraidofthisboringprocess.Janehasdecidedtousearadiatortomakedryingfaster.Buttheradiatorissmall,soitcanholdonlyonethingatatime. Janewantstoperformdryingintheminimalpossibletime.Sheaskedyoutowriteaprogramthatwillcalculatetheminimaltimeforagivensetofclothes. TherearenclothesJanehasjustwashed.Eachofthemtookaiwaterduringwashing.Everyminutetheamountofwatercontainedineachthingdecreasesbyone(ofcourse,onlyifthethingisnotcompletelydryyet).Whenamountofwatercontainedbecomeszerotheclothbecomesdryandisreadytobepacked. EveryminuteJanecanselectonethingtodryontheradiator.Theradiatorisveryhot,sotheamountofwaterinthisthingdecreasesbykthisminute(butnotlessthanzero—ifthethingcontainslessthankwater,theresultingamountofwaterwillbezero). Thetaskistominimizethetotaltimeofdryingbymeansofusingtheradiatoreffectively.Thedryingprocessendswhenalltheclothesaredry. Input Thefirstlinecontainsasingleintegern(1≤n≤100000).Thesecondlinecontainsaiseparatedbyspaces(1≤ai≤109).Thethirdlinecontainsk(1≤k≤109). Output Outputasingleinteger—theminimalpossiblenumberofminutesrequiredtodryallclothes. SampleInput sampleinput#1 3 239 5 sampleinput#2 3 236 5 SampleOutput sampleoutput#1 3 sampleoutput#2 2 |
题目大意:有n件衣服,每件衣服有一定的水量,使衣服干有两种方法:1、水分蒸发,每分钟蒸发掉一滴水2、用烘干机烘干,每分钟烘干掉k滴水。题目要输出的是是所有衣服变干的最小时间。 详见代码。
#include<iostream> #include<cstdio> #include<cmath> usingnamespacestd; #definelllonglong intmain() { intn; lla[100000+10]; lltmax; while(~scanf("%d",&n)) { tmax=0; for(inti=0;i<n;i++) { scanf("%lld",&a[i]); if(a[i]>tmax) tmax=a[i]; } llk; scanf("%lld",&k); if(k==1) { printf("%lld",tmax); continue; } lll=1,r=tmax,mid,ans=0; while(r>=l) { llsum=0; mid=(l+r)/2; for(inti=0;i<n;i++) { if(a[i]>mid) { lls=ceil((a[i]-mid)*1.0/(k-1)); sum+=s; } } if(sum>mid) l=mid+1; else r=mid-1,ans=mid; } printf("%lld\n",ans); } return0; }
相关文章推荐
- poj 3104 Drying(二分查找)
- POJ 3104 Drying (二分答案)
- poj 3104 Drying (二分)
- poj 3104 Drying(二分)
- POJ 3104 Drying ——二分
- POJ_3104_Drying_(二分,最小化最大值)
- Drying POJ - 3104 (二分)
- POJ 3104 Drying【二分】
- POJ 3104 Drying(二分枚举)
- POJ - 3104 Drying (二分搜索)
- POJ - 3104 Drying(二分)
- poj 3104 Drying (二分搜索答案)
- POJ 3104 Drying (二分求最小值)
- POJ 3104 Drying 二分搜索
- POJ 3104 Drying (二分+精度)
- POJ 3104 Drying-二分答案
- POJ 3104 - Drying(二分搜索)
- POJ 3104 Drying (二分)
- POJ 3104 Drying (二分求最小值)
- poj 3104 Drying (二分)