uva 714 - Copying Books
2012-10-08 20:51
246 查看
CopyingBooks |
scribers.Thescriberhadbeengivenabookandafterseveralmonthshefinisheditscopy.Oneofthemostfamousscriberslivedinthe15thcenturyandhisnamewasXaveriusEndricusRemiusOntiusXendrianus(Xerox).Anyway,theworkwas
veryannoyingandboring.Andtheonlywaytospeeditupwastohiremorescribers.
Onceuponatime,therewasatheaterensemblethatwantedtoplayfamousAntiqueTragedies.Thescriptsoftheseplaysweredividedintomanybooksandactorsneededmorecopiesofthem,ofcourse.Sotheyhiredmanyscriberstomakecopiesofthesebooks.
Imagineyouhavembooks(numbered
)thatmayhavedifferentnumberofpages(
)andyouwanttomakeonecopyofeachofthem.Yourtaskistodividethesebooksamong
kscribes,
.Eachbookcanbeassignedtoasinglescriberonly,andeveryscribermustgetacontinuoussequenceofbooks.
Thatmeans,thereexistsanincreasingsuccessionofnumbers
suchthat
i-thscribergetsasequenceofbookswithnumbersbetweenbi-1+1and
bi.Thetimeneededtomakeacopyofallthebooksisdeterminedbythescriberwhowasassignedthemostwork.Therefore,ourgoalistominimizethemaximumnumberofpagesassignedtoasinglescriber.Yourtaskistofindthe
optimalassignment.
Input
TheinputconsistsofNcases.ThefirstlineoftheinputcontainsonlypositiveintegerN.Thenfollowthecases.Eachcaseconsistsofexactlytwolines.Atthefirstline,therearetwointegers
mandk,
.Atthesecondline,thereareintegers
separatedbyspaces.Allthesevaluesarepositiveandlessthan10000000.
Output
Foreachcase,printexactlyoneline.Thelinemustcontaintheinputsuccessiondividedintoexactly
kpartssuchthatthemaximumsumofasinglepartshouldbeassmallaspossible.Usetheslashcharacter(`/')toseparatetheparts.Theremustbeexactlyonespacecharacterbetweenanytwosuccessivenumbersandbetweenthenumberand
theslash.
Ifthereismorethanonesolution,printtheonethatminimizestheworkassignedtothefirstscriber,thentothesecondscriberetc.Buteachscribermustbeassignedatleastonebook.
SampleInput
2 93 100200300400500600700800900 54 100100100100100
SampleOutput
100200300400500/600700/800900 100/100/100/100100 给定一组数,划分成k份,是每一份的和的最大值最小,当存在多种划分时,后面的和尽量大于前面的;
刚放完假做题奇慢YY,首先这个和一定是在这m个数中最大的到m个数[code]#include<stdio.h> #include<string.h> longlongn,m,a[510],b[510],ans[510],left,right,mid,t; longlongcheck(longlongmax) { longlongi,num=0,pos=0; memset(b,0,sizeof(b)); for(i=n;i>=1;i--) { if(pos+a[i]<=max&&i>=m-num)pos=pos+a[i]; else { ++num; pos=a[i]; b[i]=1; } } if(num+1==m) { for(i=1;i<=n;i++) ans[i]=b[i]; return1; } elsereturn0; } intmain() { longlongi; scanf("%lld",&t); while(t--) { left=0;right=0; scanf("%lld%lld",&n,&m); for(i=1;i<=n;i++) { scanf("%lld",&a[i]); right+=a[i]; if(a[i]>left)left=a[i]; } memset(ans,0,sizeof(ans)); while(left<=right) { mid=(left+right)/2; if(check(mid)==1)right=mid-1; elseleft=mid+1; } for(i=1;i<n;i++) if(ans[i]==1)printf("%lld/",a[i]); elseprintf("%lld",a[i]); printf("%lld\n",a ); } return0; }
的和之间,所以可以二分查找,重点在判断某个值的划分是否成立,倒着贪心累加,注意k组划分不能有空集[/code]
相关文章推荐
- UVa 714 Copying Books - 二分答案
- UVA 714 Copying Books
- UVA 714 Copying Books(二分查找)(未a)
- UVA 714 Copying Books 二分
- UVa 714,Copying Books
- UVA 714 Copying Books
- uva 714 Copying Books
- UVA 714 Copying Books
- uva 714 - Copying Books(二分+贪心)
- uva 714 Copying Books (二分)
- UVA - 714 Copying Books 最大值尽量小
- POJ1505&&UVa714 Copying Books(DP)
- UVa 714 Copying Books (最大值尽量小_二分+贪心)
- UVA-714/POJ-1505 Copying Books
- 【NOIP提高组2015D2T1】uva 714 copying books【二分答案】——yhx
- UVA714 Copying Books (最大值最小化)
- UVA 714 Copying Books (二分)
- uva 714 - Copying Books
- UVA 714 - Copying Books
- uva 714 Copying Books