您的位置:首页 > 其它

poj 3104 Drying(二分查找)

2015-01-29 11:10 429 查看
题目链接:http://poj.org/problem?id=3104

                                       Drying

TimeLimit:2000MSMemoryLimit:65536K
TotalSubmissions:9440Accepted:2407
Description

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;
}





                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: