杭电部分题目.docx
《杭电部分题目.docx》由会员分享,可在线阅读,更多相关《杭电部分题目.docx(42页珍藏版)》请在冰豆网上搜索。
杭电部分题目
杭电1015
Safecracker
TimeLimit:
2000/1000MS(Java/Others) MemoryLimit:
65536/32768K(Java/Others)
TotalSubmission(s):
4768 AcceptedSubmission(s):
2386
ProblemDescription
===Optechbriefing,2002/11/0206:
42CST===
"TheitemislockedinaKleinsafebehindapaintinginthesecond-floorlibrary.Kleinsafesareextremelyrare;mostofthem,alongwithKleinandhisfactory,weredestroyedinWorldWarII.FortunatelyoldBrumbaughfromresearchknewKlein'ssecretsandwrotethemdownbeforehedied.AKleinsafehastwodistinguishingfeatures:
acombinationlockthatuseslettersinsteadofnumbers,andanengravedquotationonthedoor.AKleinquotationalwayscontainsbetweenfiveandtwelvedistinctuppercaseletters,usuallyatthebeginningofsentences,andmentionsoneormorenumbers.Fiveoftheuppercaselettersformthecombinationthatopensthesafe.Bycombiningthedigitsfromallthenumbersintheappropriatewayyougetanumerictarget.(Thedetailsofconstructingthetargetnumberareclassified.)Tofindthecombinationyoumustselectfivelettersv,w,x,y,andzthatsatisfythefollowingequation,whereeachletterisreplacedbyitsordinalpositioninthealphabet(A=1,B=2,...,Z=26).Thecombinationisthenvwxyz.Ifthereismorethanonesolutionthenthecombinationistheonethatislexicographicallygreatest,i.e.,theonethatwouldappearlastinadictionary."
v-w^2+x^3-y^4+z^5=target
"Forexample,giventarget1andlettersetABCDEFGHIJKL,onepossiblesolutionisFIECB,since6-9^2+5^3-3^4+2^5=1.Thereareactuallyseveralsolutionsinthiscase,andthecombinationturnsouttobeLKEBA.Kleinthoughtitwassafetoencodethecombinationwithintheengraving,becauseitcouldtakemonthsofefforttotryallthepossibilitiesevenifyouknewthesecret.Butofcoursecomputersdidn'texistthen."
===Optechdirective,computerdivision,2002/11/0212:
30CST===
"DevelopaprogramtofindKleincombinationsinpreparationforfielddeployment.Usestandardtestmethodologyasperdepartmentalregulations.Inputconsistsofoneormorelinescontainingapositiveintegertargetlessthantwelvemillion,aspace,thenatleastfiveandatmosttwelvedistinctuppercaseletters.ThelastlinewillcontainatargetofzeroandthelettersEND;thissignalstheendoftheinput.ForeachlineoutputtheKleincombination,breaktieswithlexicographicorder,or'nosolution'ifthereisnocorrectcombination.Usetheexactformatshownbelow."
SampleInput
1ABCDEFGHIJKL
11700519ZAYEXIWOVU
3072997SOUGHT
1234567THEQUICKFROG
0END
SampleOutput
LKEBA
YOXUZ
GHOST
nosolution
#include
longget_taget(inti,intj,intk,intl,intm){
longtaget=0;
taget=i-pow((float)j,2)+pow((float)k,3)-pow((float)l,4)+pow((float)m,5);
returntaget;
}
voidsort(intarray[],intsize)
{
inti,j,temp;
for(i=0;i{for(j=0;jif(array[j]{temp=array[j];array[j]=array[j+1];array[j+1]=temp;}}} intmain(){inti,j,k,l,m,len,f;longdata,taget;charstr[12];intkey[12]={0};while(scanf("%ld%s",&data,&str)){f=0;if(0==data&&'E'==str[0]&&'N'==str[1]&&'D'==str[2])break;len=strlen(str);if(len<5||len>12)break;for(i=0;ikey[i]=str[i]-'A'+1;}sort(key,len);for(i=0;ifor(j=0;jif(i==j)continue;for(k=0;kif(k==i||k==j)continue;for(l=0;lif(l==k||l==i||l==j)continue;for(m=0;mif(m==l||m==k||m==j||l==i)continue;taget=get_taget(key[i],key[j],key[k],key[l],key[m]);if(taget==data){f=1;key[i]=key[i]+64;key[j]=key[j]+64;key[k]=key[k]+64;key[l]=key[l]+64;key[m]=key[m]+64;printf("%c%c%c%c%c\n",key[i],key[j],key[k],key[l],key[m]);}}}}}}if(f==0)printf("nosolution\n");}return0;} 杭电1017:AMathematicalCuriosityTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):16821 AcceptedSubmission(s):5238 ProblemDescriptionGiventwointegersnandm,countthenumberofpairsofintegers(a,b)suchthat0Thisproblemcontainsmultipletestcases!ThefirstlineofamultipleinputisanintegerN,thenablanklinefollowedbyNinputblocks.Eachinputblockisintheformatindicatedintheproblemdescription.Thereisablanklinebetweeninputblocks.TheoutputformatconsistsofNoutputblocks.Thereisablanklinebetweenoutputblocks. InputYouwillbegivenanumberofcasesintheinput.Eachcaseisspecifiedbyalinecontainingtheintegersnandm.Theendofinputisindicatedbyacaseinwhichn=m=0.Youmayassumethat0 OutputForeachcase,printthecasenumberaswellasthenumberofpairs(a,b)satisfyingthegivenproperty.Printtheoutputforeachcaseononelineintheformatasshownbelow. SampleInput110120330400 SampleOutputCase1:2Case2:4Case3:5#includevoidmain(){intN;while(scanf("%d",&N)!=EOF){intkey;for(key=0;key{intn,m,x=0;while(scanf("%d%d",&n,&m)!=EOF){inti,j,count=0;if(n==0&&m==0)break;for(i=1;i{for(j=i+1;j{if((i*i+j*j+m)%(i*j)==0){count++;}}}printf("Case%d:%d\n",++x,count);}if(key!=N-1){printf("\n");}}} } 杭电1019LeastCommonMultipleTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):17599 AcceptedSubmission(s):6554 ProblemDescriptionTheleastcommonmultiple(LCM)ofasetofpositiveintegersisthesmallestpositiveintegerwhichisdivisiblebyallthenumbersintheset.Forexample,theLCMof5,7and15is105. InputInputwillconsistofmultipleprobleminstances.Thefirstlineoftheinputwillcontainasingleintegerindicatingthenumberofprobleminstances.Eachinstancewillconsistofasinglelineoftheformmn1n2n3...nmwheremisthenumberofintegersinthesetandn1...nmaretheintegers.Allintegerswillbepositiveandliewithintherangeofa32-bitinteger. OutputForeachprobleminstance,outputasinglelinecontainingthecorrespondingLCM.Allresultswilllieintherangeofa32-bitinteger. SampleInput235715641029693612877921 SampleOutput10510296 SourceEastCentralNorthAmerica2003,Practice #includeintLCM(intm,intn){intlcm,s,r,t,mm,nn;mm=m;nn=n;if(m{t=m;m=n;n=t;}while(n!=0){r=m%n;m=n;n=r;}lcm=mm/m*nn;returnlcm;}intmain(){intt;intnum[1000];inti,n;while(scanf("%d",&t)!=EOF){while(t--){scanf("%d",&n);for(i=0;i{scanf("%d",&num[i]);}for(i=0;i{num[i+1]=LCM(num[i],num[i+1]);}printf("%d\n",num[i]);}}return0;}杭电1020EncodingTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):17004 AcceptedSubmission(s):7270 ProblemDescriptionGivenastringcontainingonly'A'-'Z',wecouldencodeitusingthefollowingmethod: 1.Eachsub-stringcontainingksamecharactersshouldbeencodedto"kX"where"X"istheonlycharacterinthissub-string.2.Ifthelengthofthesub-stringis1,'1'shouldbeignored. InputThefirstlinecontainsanintegerN(1<=N<=100)whichindicatesthenumberoftestcases.ThenextNlinescontainNstrings.Eachstringconsistsofonly'A'-'Z'andthelengthislessthan10000. OutputForeachtestcase,outputtheencodedstringinaline. SampleInput2ABCABBCCC SampleOutputABCA2B3C #includevoidmain(){intn;chara[10000];while(scanf("%d",&n)!=EOF){inti;getchar();while(n--){gets(a);for(i=0;a[i]!='\0';i++){inttemp=1;while(a[i]==a[i+1]){temp++;i++;}if(temp==1)printf("%c",a[i]);elseprintf("%d%c",temp,a[i]);}printf("\n");}}}杭电1166敌兵布阵TimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):20003 AcceptedSubmission(s):8757 ProblemDescriptionC国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人数都有可能发生变动,可能增加或减少若干人手,但这些都逃不过C国的监视。中央情报局要研究敌人究竟演习什么战术,所以Tidy要随时向Derek汇报某一段连续的工兵营地一共有多少人,例如Derek问:“Tidy,马上汇报第3个营地到第10个营地共有多少人!”Tidy就要马上开始计算这一段的总人数并汇报。但敌兵营地的人数经常变动,而Derek每次询问的段都不一样,所以Tidy不得不每次都一个一个营地的去数,很快就精疲力尽了,Derek对Tidy的计算速度越来越不满:"你个死肥仔,算得这么慢,我炒你鱿鱼!”Tidy想:“你自己来算算看,这可真是一项累人的工作!我恨不得你炒我鱿鱼呢!”无奈之下,Tidy只好打电话向计算机专家Windbreaker求救,Windbreaker说:“死肥仔,叫你平时做多点acm题和看多点算法书,现在尝到苦果了吧!”Tidy说:"我知错了。。。"但Windbreaker已经挂掉电话了。Tidy很苦恼,这么算他真的会崩溃的,聪明的读者,你能写个程序帮他完成这项工作吗?不过如果你的程序效率不够高的话,Tidy还是会受到Derek的责骂的. Input第一行一个整数T,表示有T组数据。每组数据第一行一个正整数N(N<=50000),表示敌人有N个工兵营地,接下来有N个正整数,第i个正整数ai代表第i个工兵营地里开始时有ai个人(1<=ai<=50)。接下来每行有一条命令,命令有4种形式:(1)Addij,i和j为正整数,表示第i个营地增加j个人(j不超过30)(2)Subij,i和j为正整数,表示第i个营地减少j个人(j不超过30);(3)Queryij,i和j为正整数,i<=j,表示询问第i到第j个营地的总人数;(4)End表示结束,这条命令在每组数据最后出现;每组数据最多有40000条命令 Output对第i组数据,首先输出“Casei:”和回车,对于每个Query询问,输出一个整数并回车,表示询问的段中的总人数,这个数保持在int以内。 SampleInput11012345678910Query13Add36Query27Sub102Add63Query310End SampleOutputCase1:63359(线段树)#include#include#defineMAX50010intnum[MAX];typedefstructnode{intlchild;intrchild;intnumber;};nodea[4*MAX];intbulit(ints,intt,intstep){intk,mid,x,y;if(s==t){a[step].
for(j=0;jif(array[j]{temp=array[j];array[j]=array[j+1];array[j+1]=temp;}}} intmain(){inti,j,k,l,m,len,f;longdata,taget;charstr[12];intkey[12]={0};while(scanf("%ld%s",&data,&str)){f=0;if(0==data&&'E'==str[0]&&'N'==str[1]&&'D'==str[2])break;len=strlen(str);if(len<5||len>12)break;for(i=0;ikey[i]=str[i]-'A'+1;}sort(key,len);for(i=0;ifor(j=0;jif(i==j)continue;for(k=0;kif(k==i||k==j)continue;for(l=0;lif(l==k||l==i||l==j)continue;for(m=0;mif(m==l||m==k||m==j||l==i)continue;taget=get_taget(key[i],key[j],key[k],key[l],key[m]);if(taget==data){f=1;key[i]=key[i]+64;key[j]=key[j]+64;key[k]=key[k]+64;key[l]=key[l]+64;key[m]=key[m]+64;printf("%c%c%c%c%c\n",key[i],key[j],key[k],key[l],key[m]);}}}}}}if(f==0)printf("nosolution\n");}return0;} 杭电1017:AMathematicalCuriosityTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):16821 AcceptedSubmission(s):5238 ProblemDescriptionGiventwointegersnandm,countthenumberofpairsofintegers(a,b)suchthat0Thisproblemcontainsmultipletestcases!ThefirstlineofamultipleinputisanintegerN,thenablanklinefollowedbyNinputblocks.Eachinputblockisintheformatindicatedintheproblemdescription.Thereisablanklinebetweeninputblocks.TheoutputformatconsistsofNoutputblocks.Thereisablanklinebetweenoutputblocks. InputYouwillbegivenanumberofcasesintheinput.Eachcaseisspecifiedbyalinecontainingtheintegersnandm.Theendofinputisindicatedbyacaseinwhichn=m=0.Youmayassumethat0 OutputForeachcase,printthecasenumberaswellasthenumberofpairs(a,b)satisfyingthegivenproperty.Printtheoutputforeachcaseononelineintheformatasshownbelow. SampleInput110120330400 SampleOutputCase1:2Case2:4Case3:5#includevoidmain(){intN;while(scanf("%d",&N)!=EOF){intkey;for(key=0;key{intn,m,x=0;while(scanf("%d%d",&n,&m)!=EOF){inti,j,count=0;if(n==0&&m==0)break;for(i=1;i{for(j=i+1;j{if((i*i+j*j+m)%(i*j)==0){count++;}}}printf("Case%d:%d\n",++x,count);}if(key!=N-1){printf("\n");}}} } 杭电1019LeastCommonMultipleTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):17599 AcceptedSubmission(s):6554 ProblemDescriptionTheleastcommonmultiple(LCM)ofasetofpositiveintegersisthesmallestpositiveintegerwhichisdivisiblebyallthenumbersintheset.Forexample,theLCMof5,7and15is105. InputInputwillconsistofmultipleprobleminstances.Thefirstlineoftheinputwillcontainasingleintegerindicatingthenumberofprobleminstances.Eachinstancewillconsistofasinglelineoftheformmn1n2n3...nmwheremisthenumberofintegersinthesetandn1...nmaretheintegers.Allintegerswillbepositiveandliewithintherangeofa32-bitinteger. OutputForeachprobleminstance,outputasinglelinecontainingthecorrespondingLCM.Allresultswilllieintherangeofa32-bitinteger. SampleInput235715641029693612877921 SampleOutput10510296 SourceEastCentralNorthAmerica2003,Practice #includeintLCM(intm,intn){intlcm,s,r,t,mm,nn;mm=m;nn=n;if(m{t=m;m=n;n=t;}while(n!=0){r=m%n;m=n;n=r;}lcm=mm/m*nn;returnlcm;}intmain(){intt;intnum[1000];inti,n;while(scanf("%d",&t)!=EOF){while(t--){scanf("%d",&n);for(i=0;i{scanf("%d",&num[i]);}for(i=0;i{num[i+1]=LCM(num[i],num[i+1]);}printf("%d\n",num[i]);}}return0;}杭电1020EncodingTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):17004 AcceptedSubmission(s):7270 ProblemDescriptionGivenastringcontainingonly'A'-'Z',wecouldencodeitusingthefollowingmethod: 1.Eachsub-stringcontainingksamecharactersshouldbeencodedto"kX"where"X"istheonlycharacterinthissub-string.2.Ifthelengthofthesub-stringis1,'1'shouldbeignored. InputThefirstlinecontainsanintegerN(1<=N<=100)whichindicatesthenumberoftestcases.ThenextNlinescontainNstrings.Eachstringconsistsofonly'A'-'Z'andthelengthislessthan10000. OutputForeachtestcase,outputtheencodedstringinaline. SampleInput2ABCABBCCC SampleOutputABCA2B3C #includevoidmain(){intn;chara[10000];while(scanf("%d",&n)!=EOF){inti;getchar();while(n--){gets(a);for(i=0;a[i]!='\0';i++){inttemp=1;while(a[i]==a[i+1]){temp++;i++;}if(temp==1)printf("%c",a[i]);elseprintf("%d%c",temp,a[i]);}printf("\n");}}}杭电1166敌兵布阵TimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):20003 AcceptedSubmission(s):8757 ProblemDescriptionC国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人数都有可能发生变动,可能增加或减少若干人手,但这些都逃不过C国的监视。中央情报局要研究敌人究竟演习什么战术,所以Tidy要随时向Derek汇报某一段连续的工兵营地一共有多少人,例如Derek问:“Tidy,马上汇报第3个营地到第10个营地共有多少人!”Tidy就要马上开始计算这一段的总人数并汇报。但敌兵营地的人数经常变动,而Derek每次询问的段都不一样,所以Tidy不得不每次都一个一个营地的去数,很快就精疲力尽了,Derek对Tidy的计算速度越来越不满:"你个死肥仔,算得这么慢,我炒你鱿鱼!”Tidy想:“你自己来算算看,这可真是一项累人的工作!我恨不得你炒我鱿鱼呢!”无奈之下,Tidy只好打电话向计算机专家Windbreaker求救,Windbreaker说:“死肥仔,叫你平时做多点acm题和看多点算法书,现在尝到苦果了吧!”Tidy说:"我知错了。。。"但Windbreaker已经挂掉电话了。Tidy很苦恼,这么算他真的会崩溃的,聪明的读者,你能写个程序帮他完成这项工作吗?不过如果你的程序效率不够高的话,Tidy还是会受到Derek的责骂的. Input第一行一个整数T,表示有T组数据。每组数据第一行一个正整数N(N<=50000),表示敌人有N个工兵营地,接下来有N个正整数,第i个正整数ai代表第i个工兵营地里开始时有ai个人(1<=ai<=50)。接下来每行有一条命令,命令有4种形式:(1)Addij,i和j为正整数,表示第i个营地增加j个人(j不超过30)(2)Subij,i和j为正整数,表示第i个营地减少j个人(j不超过30);(3)Queryij,i和j为正整数,i<=j,表示询问第i到第j个营地的总人数;(4)End表示结束,这条命令在每组数据最后出现;每组数据最多有40000条命令 Output对第i组数据,首先输出“Casei:”和回车,对于每个Query询问,输出一个整数并回车,表示询问的段中的总人数,这个数保持在int以内。 SampleInput11012345678910Query13Add36Query27Sub102Add63Query310End SampleOutputCase1:63359(线段树)#include#include#defineMAX50010intnum[MAX];typedefstructnode{intlchild;intrchild;intnumber;};nodea[4*MAX];intbulit(ints,intt,intstep){intk,mid,x,y;if(s==t){a[step].
if(array[j]{temp=array[j];array[j]=array[j+1];array[j+1]=temp;}}} intmain(){inti,j,k,l,m,len,f;longdata,taget;charstr[12];intkey[12]={0};while(scanf("%ld%s",&data,&str)){f=0;if(0==data&&'E'==str[0]&&'N'==str[1]&&'D'==str[2])break;len=strlen(str);if(len<5||len>12)break;for(i=0;ikey[i]=str[i]-'A'+1;}sort(key,len);for(i=0;ifor(j=0;jif(i==j)continue;for(k=0;kif(k==i||k==j)continue;for(l=0;lif(l==k||l==i||l==j)continue;for(m=0;mif(m==l||m==k||m==j||l==i)continue;taget=get_taget(key[i],key[j],key[k],key[l],key[m]);if(taget==data){f=1;key[i]=key[i]+64;key[j]=key[j]+64;key[k]=key[k]+64;key[l]=key[l]+64;key[m]=key[m]+64;printf("%c%c%c%c%c\n",key[i],key[j],key[k],key[l],key[m]);}}}}}}if(f==0)printf("nosolution\n");}return0;} 杭电1017:AMathematicalCuriosityTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):16821 AcceptedSubmission(s):5238 ProblemDescriptionGiventwointegersnandm,countthenumberofpairsofintegers(a,b)suchthat0Thisproblemcontainsmultipletestcases!ThefirstlineofamultipleinputisanintegerN,thenablanklinefollowedbyNinputblocks.Eachinputblockisintheformatindicatedintheproblemdescription.Thereisablanklinebetweeninputblocks.TheoutputformatconsistsofNoutputblocks.Thereisablanklinebetweenoutputblocks. InputYouwillbegivenanumberofcasesintheinput.Eachcaseisspecifiedbyalinecontainingtheintegersnandm.Theendofinputisindicatedbyacaseinwhichn=m=0.Youmayassumethat0 OutputForeachcase,printthecasenumberaswellasthenumberofpairs(a,b)satisfyingthegivenproperty.Printtheoutputforeachcaseononelineintheformatasshownbelow. SampleInput110120330400 SampleOutputCase1:2Case2:4Case3:5#includevoidmain(){intN;while(scanf("%d",&N)!=EOF){intkey;for(key=0;key{intn,m,x=0;while(scanf("%d%d",&n,&m)!=EOF){inti,j,count=0;if(n==0&&m==0)break;for(i=1;i{for(j=i+1;j{if((i*i+j*j+m)%(i*j)==0){count++;}}}printf("Case%d:%d\n",++x,count);}if(key!=N-1){printf("\n");}}} } 杭电1019LeastCommonMultipleTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):17599 AcceptedSubmission(s):6554 ProblemDescriptionTheleastcommonmultiple(LCM)ofasetofpositiveintegersisthesmallestpositiveintegerwhichisdivisiblebyallthenumbersintheset.Forexample,theLCMof5,7and15is105. InputInputwillconsistofmultipleprobleminstances.Thefirstlineoftheinputwillcontainasingleintegerindicatingthenumberofprobleminstances.Eachinstancewillconsistofasinglelineoftheformmn1n2n3...nmwheremisthenumberofintegersinthesetandn1...nmaretheintegers.Allintegerswillbepositiveandliewithintherangeofa32-bitinteger. OutputForeachprobleminstance,outputasinglelinecontainingthecorrespondingLCM.Allresultswilllieintherangeofa32-bitinteger. SampleInput235715641029693612877921 SampleOutput10510296 SourceEastCentralNorthAmerica2003,Practice #includeintLCM(intm,intn){intlcm,s,r,t,mm,nn;mm=m;nn=n;if(m{t=m;m=n;n=t;}while(n!=0){r=m%n;m=n;n=r;}lcm=mm/m*nn;returnlcm;}intmain(){intt;intnum[1000];inti,n;while(scanf("%d",&t)!=EOF){while(t--){scanf("%d",&n);for(i=0;i{scanf("%d",&num[i]);}for(i=0;i{num[i+1]=LCM(num[i],num[i+1]);}printf("%d\n",num[i]);}}return0;}杭电1020EncodingTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):17004 AcceptedSubmission(s):7270 ProblemDescriptionGivenastringcontainingonly'A'-'Z',wecouldencodeitusingthefollowingmethod: 1.Eachsub-stringcontainingksamecharactersshouldbeencodedto"kX"where"X"istheonlycharacterinthissub-string.2.Ifthelengthofthesub-stringis1,'1'shouldbeignored. InputThefirstlinecontainsanintegerN(1<=N<=100)whichindicatesthenumberoftestcases.ThenextNlinescontainNstrings.Eachstringconsistsofonly'A'-'Z'andthelengthislessthan10000. OutputForeachtestcase,outputtheencodedstringinaline. SampleInput2ABCABBCCC SampleOutputABCA2B3C #includevoidmain(){intn;chara[10000];while(scanf("%d",&n)!=EOF){inti;getchar();while(n--){gets(a);for(i=0;a[i]!='\0';i++){inttemp=1;while(a[i]==a[i+1]){temp++;i++;}if(temp==1)printf("%c",a[i]);elseprintf("%d%c",temp,a[i]);}printf("\n");}}}杭电1166敌兵布阵TimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):20003 AcceptedSubmission(s):8757 ProblemDescriptionC国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人数都有可能发生变动,可能增加或减少若干人手,但这些都逃不过C国的监视。中央情报局要研究敌人究竟演习什么战术,所以Tidy要随时向Derek汇报某一段连续的工兵营地一共有多少人,例如Derek问:“Tidy,马上汇报第3个营地到第10个营地共有多少人!”Tidy就要马上开始计算这一段的总人数并汇报。但敌兵营地的人数经常变动,而Derek每次询问的段都不一样,所以Tidy不得不每次都一个一个营地的去数,很快就精疲力尽了,Derek对Tidy的计算速度越来越不满:"你个死肥仔,算得这么慢,我炒你鱿鱼!”Tidy想:“你自己来算算看,这可真是一项累人的工作!我恨不得你炒我鱿鱼呢!”无奈之下,Tidy只好打电话向计算机专家Windbreaker求救,Windbreaker说:“死肥仔,叫你平时做多点acm题和看多点算法书,现在尝到苦果了吧!”Tidy说:"我知错了。。。"但Windbreaker已经挂掉电话了。Tidy很苦恼,这么算他真的会崩溃的,聪明的读者,你能写个程序帮他完成这项工作吗?不过如果你的程序效率不够高的话,Tidy还是会受到Derek的责骂的. Input第一行一个整数T,表示有T组数据。每组数据第一行一个正整数N(N<=50000),表示敌人有N个工兵营地,接下来有N个正整数,第i个正整数ai代表第i个工兵营地里开始时有ai个人(1<=ai<=50)。接下来每行有一条命令,命令有4种形式:(1)Addij,i和j为正整数,表示第i个营地增加j个人(j不超过30)(2)Subij,i和j为正整数,表示第i个营地减少j个人(j不超过30);(3)Queryij,i和j为正整数,i<=j,表示询问第i到第j个营地的总人数;(4)End表示结束,这条命令在每组数据最后出现;每组数据最多有40000条命令 Output对第i组数据,首先输出“Casei:”和回车,对于每个Query询问,输出一个整数并回车,表示询问的段中的总人数,这个数保持在int以内。 SampleInput11012345678910Query13Add36Query27Sub102Add63Query310End SampleOutputCase1:63359(线段树)#include#include#defineMAX50010intnum[MAX];typedefstructnode{intlchild;intrchild;intnumber;};nodea[4*MAX];intbulit(ints,intt,intstep){intk,mid,x,y;if(s==t){a[step].
temp=array[j];
array[j]=array[j+1];
array[j+1]=temp;
intmain(){
inti,j,k,l,m,len,f;
longdata,taget;
charstr[12];
intkey[12]={0};
while(scanf("%ld%s",&data,&str)){
f=0;
if(0==data&&'E'==str[0]&&'N'==str[1]&&'D'==str[2])
break;
len=strlen(str);
if(len<5||len>12)
for(i=0;ikey[i]=str[i]-'A'+1;}sort(key,len);for(i=0;ifor(j=0;jif(i==j)continue;for(k=0;kif(k==i||k==j)continue;for(l=0;lif(l==k||l==i||l==j)continue;for(m=0;mif(m==l||m==k||m==j||l==i)continue;taget=get_taget(key[i],key[j],key[k],key[l],key[m]);if(taget==data){f=1;key[i]=key[i]+64;key[j]=key[j]+64;key[k]=key[k]+64;key[l]=key[l]+64;key[m]=key[m]+64;printf("%c%c%c%c%c\n",key[i],key[j],key[k],key[l],key[m]);}}}}}}if(f==0)printf("nosolution\n");}return0;} 杭电1017:AMathematicalCuriosityTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):16821 AcceptedSubmission(s):5238 ProblemDescriptionGiventwointegersnandm,countthenumberofpairsofintegers(a,b)suchthat0Thisproblemcontainsmultipletestcases!ThefirstlineofamultipleinputisanintegerN,thenablanklinefollowedbyNinputblocks.Eachinputblockisintheformatindicatedintheproblemdescription.Thereisablanklinebetweeninputblocks.TheoutputformatconsistsofNoutputblocks.Thereisablanklinebetweenoutputblocks. InputYouwillbegivenanumberofcasesintheinput.Eachcaseisspecifiedbyalinecontainingtheintegersnandm.Theendofinputisindicatedbyacaseinwhichn=m=0.Youmayassumethat0 OutputForeachcase,printthecasenumberaswellasthenumberofpairs(a,b)satisfyingthegivenproperty.Printtheoutputforeachcaseononelineintheformatasshownbelow. SampleInput110120330400 SampleOutputCase1:2Case2:4Case3:5#includevoidmain(){intN;while(scanf("%d",&N)!=EOF){intkey;for(key=0;key{intn,m,x=0;while(scanf("%d%d",&n,&m)!=EOF){inti,j,count=0;if(n==0&&m==0)break;for(i=1;i{for(j=i+1;j{if((i*i+j*j+m)%(i*j)==0){count++;}}}printf("Case%d:%d\n",++x,count);}if(key!=N-1){printf("\n");}}} } 杭电1019LeastCommonMultipleTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):17599 AcceptedSubmission(s):6554 ProblemDescriptionTheleastcommonmultiple(LCM)ofasetofpositiveintegersisthesmallestpositiveintegerwhichisdivisiblebyallthenumbersintheset.Forexample,theLCMof5,7and15is105. InputInputwillconsistofmultipleprobleminstances.Thefirstlineoftheinputwillcontainasingleintegerindicatingthenumberofprobleminstances.Eachinstancewillconsistofasinglelineoftheformmn1n2n3...nmwheremisthenumberofintegersinthesetandn1...nmaretheintegers.Allintegerswillbepositiveandliewithintherangeofa32-bitinteger. OutputForeachprobleminstance,outputasinglelinecontainingthecorrespondingLCM.Allresultswilllieintherangeofa32-bitinteger. SampleInput235715641029693612877921 SampleOutput10510296 SourceEastCentralNorthAmerica2003,Practice #includeintLCM(intm,intn){intlcm,s,r,t,mm,nn;mm=m;nn=n;if(m{t=m;m=n;n=t;}while(n!=0){r=m%n;m=n;n=r;}lcm=mm/m*nn;returnlcm;}intmain(){intt;intnum[1000];inti,n;while(scanf("%d",&t)!=EOF){while(t--){scanf("%d",&n);for(i=0;i{scanf("%d",&num[i]);}for(i=0;i{num[i+1]=LCM(num[i],num[i+1]);}printf("%d\n",num[i]);}}return0;}杭电1020EncodingTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):17004 AcceptedSubmission(s):7270 ProblemDescriptionGivenastringcontainingonly'A'-'Z',wecouldencodeitusingthefollowingmethod: 1.Eachsub-stringcontainingksamecharactersshouldbeencodedto"kX"where"X"istheonlycharacterinthissub-string.2.Ifthelengthofthesub-stringis1,'1'shouldbeignored. InputThefirstlinecontainsanintegerN(1<=N<=100)whichindicatesthenumberoftestcases.ThenextNlinescontainNstrings.Eachstringconsistsofonly'A'-'Z'andthelengthislessthan10000. OutputForeachtestcase,outputtheencodedstringinaline. SampleInput2ABCABBCCC SampleOutputABCA2B3C #includevoidmain(){intn;chara[10000];while(scanf("%d",&n)!=EOF){inti;getchar();while(n--){gets(a);for(i=0;a[i]!='\0';i++){inttemp=1;while(a[i]==a[i+1]){temp++;i++;}if(temp==1)printf("%c",a[i]);elseprintf("%d%c",temp,a[i]);}printf("\n");}}}杭电1166敌兵布阵TimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):20003 AcceptedSubmission(s):8757 ProblemDescriptionC国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人数都有可能发生变动,可能增加或减少若干人手,但这些都逃不过C国的监视。中央情报局要研究敌人究竟演习什么战术,所以Tidy要随时向Derek汇报某一段连续的工兵营地一共有多少人,例如Derek问:“Tidy,马上汇报第3个营地到第10个营地共有多少人!”Tidy就要马上开始计算这一段的总人数并汇报。但敌兵营地的人数经常变动,而Derek每次询问的段都不一样,所以Tidy不得不每次都一个一个营地的去数,很快就精疲力尽了,Derek对Tidy的计算速度越来越不满:"你个死肥仔,算得这么慢,我炒你鱿鱼!”Tidy想:“你自己来算算看,这可真是一项累人的工作!我恨不得你炒我鱿鱼呢!”无奈之下,Tidy只好打电话向计算机专家Windbreaker求救,Windbreaker说:“死肥仔,叫你平时做多点acm题和看多点算法书,现在尝到苦果了吧!”Tidy说:"我知错了。。。"但Windbreaker已经挂掉电话了。Tidy很苦恼,这么算他真的会崩溃的,聪明的读者,你能写个程序帮他完成这项工作吗?不过如果你的程序效率不够高的话,Tidy还是会受到Derek的责骂的. Input第一行一个整数T,表示有T组数据。每组数据第一行一个正整数N(N<=50000),表示敌人有N个工兵营地,接下来有N个正整数,第i个正整数ai代表第i个工兵营地里开始时有ai个人(1<=ai<=50)。接下来每行有一条命令,命令有4种形式:(1)Addij,i和j为正整数,表示第i个营地增加j个人(j不超过30)(2)Subij,i和j为正整数,表示第i个营地减少j个人(j不超过30);(3)Queryij,i和j为正整数,i<=j,表示询问第i到第j个营地的总人数;(4)End表示结束,这条命令在每组数据最后出现;每组数据最多有40000条命令 Output对第i组数据,首先输出“Casei:”和回车,对于每个Query询问,输出一个整数并回车,表示询问的段中的总人数,这个数保持在int以内。 SampleInput11012345678910Query13Add36Query27Sub102Add63Query310End SampleOutputCase1:63359(线段树)#include#include#defineMAX50010intnum[MAX];typedefstructnode{intlchild;intrchild;intnumber;};nodea[4*MAX];intbulit(ints,intt,intstep){intk,mid,x,y;if(s==t){a[step].
key[i]=str[i]-'A'+1;
sort(key,len);
for(i=0;ifor(j=0;jif(i==j)continue;for(k=0;kif(k==i||k==j)continue;for(l=0;lif(l==k||l==i||l==j)continue;for(m=0;mif(m==l||m==k||m==j||l==i)continue;taget=get_taget(key[i],key[j],key[k],key[l],key[m]);if(taget==data){f=1;key[i]=key[i]+64;key[j]=key[j]+64;key[k]=key[k]+64;key[l]=key[l]+64;key[m]=key[m]+64;printf("%c%c%c%c%c\n",key[i],key[j],key[k],key[l],key[m]);}}}}}}if(f==0)printf("nosolution\n");}return0;} 杭电1017:AMathematicalCuriosityTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):16821 AcceptedSubmission(s):5238 ProblemDescriptionGiventwointegersnandm,countthenumberofpairsofintegers(a,b)suchthat0Thisproblemcontainsmultipletestcases!ThefirstlineofamultipleinputisanintegerN,thenablanklinefollowedbyNinputblocks.Eachinputblockisintheformatindicatedintheproblemdescription.Thereisablanklinebetweeninputblocks.TheoutputformatconsistsofNoutputblocks.Thereisablanklinebetweenoutputblocks. InputYouwillbegivenanumberofcasesintheinput.Eachcaseisspecifiedbyalinecontainingtheintegersnandm.Theendofinputisindicatedbyacaseinwhichn=m=0.Youmayassumethat0 OutputForeachcase,printthecasenumberaswellasthenumberofpairs(a,b)satisfyingthegivenproperty.Printtheoutputforeachcaseononelineintheformatasshownbelow. SampleInput110120330400 SampleOutputCase1:2Case2:4Case3:5#includevoidmain(){intN;while(scanf("%d",&N)!=EOF){intkey;for(key=0;key{intn,m,x=0;while(scanf("%d%d",&n,&m)!=EOF){inti,j,count=0;if(n==0&&m==0)break;for(i=1;i{for(j=i+1;j{if((i*i+j*j+m)%(i*j)==0){count++;}}}printf("Case%d:%d\n",++x,count);}if(key!=N-1){printf("\n");}}} } 杭电1019LeastCommonMultipleTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):17599 AcceptedSubmission(s):6554 ProblemDescriptionTheleastcommonmultiple(LCM)ofasetofpositiveintegersisthesmallestpositiveintegerwhichisdivisiblebyallthenumbersintheset.Forexample,theLCMof5,7and15is105. InputInputwillconsistofmultipleprobleminstances.Thefirstlineoftheinputwillcontainasingleintegerindicatingthenumberofprobleminstances.Eachinstancewillconsistofasinglelineoftheformmn1n2n3...nmwheremisthenumberofintegersinthesetandn1...nmaretheintegers.Allintegerswillbepositiveandliewithintherangeofa32-bitinteger. OutputForeachprobleminstance,outputasinglelinecontainingthecorrespondingLCM.Allresultswilllieintherangeofa32-bitinteger. SampleInput235715641029693612877921 SampleOutput10510296 SourceEastCentralNorthAmerica2003,Practice #includeintLCM(intm,intn){intlcm,s,r,t,mm,nn;mm=m;nn=n;if(m{t=m;m=n;n=t;}while(n!=0){r=m%n;m=n;n=r;}lcm=mm/m*nn;returnlcm;}intmain(){intt;intnum[1000];inti,n;while(scanf("%d",&t)!=EOF){while(t--){scanf("%d",&n);for(i=0;i{scanf("%d",&num[i]);}for(i=0;i{num[i+1]=LCM(num[i],num[i+1]);}printf("%d\n",num[i]);}}return0;}杭电1020EncodingTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):17004 AcceptedSubmission(s):7270 ProblemDescriptionGivenastringcontainingonly'A'-'Z',wecouldencodeitusingthefollowingmethod: 1.Eachsub-stringcontainingksamecharactersshouldbeencodedto"kX"where"X"istheonlycharacterinthissub-string.2.Ifthelengthofthesub-stringis1,'1'shouldbeignored. InputThefirstlinecontainsanintegerN(1<=N<=100)whichindicatesthenumberoftestcases.ThenextNlinescontainNstrings.Eachstringconsistsofonly'A'-'Z'andthelengthislessthan10000. OutputForeachtestcase,outputtheencodedstringinaline. SampleInput2ABCABBCCC SampleOutputABCA2B3C #includevoidmain(){intn;chara[10000];while(scanf("%d",&n)!=EOF){inti;getchar();while(n--){gets(a);for(i=0;a[i]!='\0';i++){inttemp=1;while(a[i]==a[i+1]){temp++;i++;}if(temp==1)printf("%c",a[i]);elseprintf("%d%c",temp,a[i]);}printf("\n");}}}杭电1166敌兵布阵TimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):20003 AcceptedSubmission(s):8757 ProblemDescriptionC国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人数都有可能发生变动,可能增加或减少若干人手,但这些都逃不过C国的监视。中央情报局要研究敌人究竟演习什么战术,所以Tidy要随时向Derek汇报某一段连续的工兵营地一共有多少人,例如Derek问:“Tidy,马上汇报第3个营地到第10个营地共有多少人!”Tidy就要马上开始计算这一段的总人数并汇报。但敌兵营地的人数经常变动,而Derek每次询问的段都不一样,所以Tidy不得不每次都一个一个营地的去数,很快就精疲力尽了,Derek对Tidy的计算速度越来越不满:"你个死肥仔,算得这么慢,我炒你鱿鱼!”Tidy想:“你自己来算算看,这可真是一项累人的工作!我恨不得你炒我鱿鱼呢!”无奈之下,Tidy只好打电话向计算机专家Windbreaker求救,Windbreaker说:“死肥仔,叫你平时做多点acm题和看多点算法书,现在尝到苦果了吧!”Tidy说:"我知错了。。。"但Windbreaker已经挂掉电话了。Tidy很苦恼,这么算他真的会崩溃的,聪明的读者,你能写个程序帮他完成这项工作吗?不过如果你的程序效率不够高的话,Tidy还是会受到Derek的责骂的. Input第一行一个整数T,表示有T组数据。每组数据第一行一个正整数N(N<=50000),表示敌人有N个工兵营地,接下来有N个正整数,第i个正整数ai代表第i个工兵营地里开始时有ai个人(1<=ai<=50)。接下来每行有一条命令,命令有4种形式:(1)Addij,i和j为正整数,表示第i个营地增加j个人(j不超过30)(2)Subij,i和j为正整数,表示第i个营地减少j个人(j不超过30);(3)Queryij,i和j为正整数,i<=j,表示询问第i到第j个营地的总人数;(4)End表示结束,这条命令在每组数据最后出现;每组数据最多有40000条命令 Output对第i组数据,首先输出“Casei:”和回车,对于每个Query询问,输出一个整数并回车,表示询问的段中的总人数,这个数保持在int以内。 SampleInput11012345678910Query13Add36Query27Sub102Add63Query310End SampleOutputCase1:63359(线段树)#include#include#defineMAX50010intnum[MAX];typedefstructnode{intlchild;intrchild;intnumber;};nodea[4*MAX];intbulit(ints,intt,intstep){intk,mid,x,y;if(s==t){a[step].
for(j=0;jif(i==j)continue;for(k=0;kif(k==i||k==j)continue;for(l=0;lif(l==k||l==i||l==j)continue;for(m=0;mif(m==l||m==k||m==j||l==i)continue;taget=get_taget(key[i],key[j],key[k],key[l],key[m]);if(taget==data){f=1;key[i]=key[i]+64;key[j]=key[j]+64;key[k]=key[k]+64;key[l]=key[l]+64;key[m]=key[m]+64;printf("%c%c%c%c%c\n",key[i],key[j],key[k],key[l],key[m]);}}}}}}if(f==0)printf("nosolution\n");}return0;} 杭电1017:AMathematicalCuriosityTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):16821 AcceptedSubmission(s):5238 ProblemDescriptionGiventwointegersnandm,countthenumberofpairsofintegers(a,b)suchthat0Thisproblemcontainsmultipletestcases!ThefirstlineofamultipleinputisanintegerN,thenablanklinefollowedbyNinputblocks.Eachinputblockisintheformatindicatedintheproblemdescription.Thereisablanklinebetweeninputblocks.TheoutputformatconsistsofNoutputblocks.Thereisablanklinebetweenoutputblocks. InputYouwillbegivenanumberofcasesintheinput.Eachcaseisspecifiedbyalinecontainingtheintegersnandm.Theendofinputisindicatedbyacaseinwhichn=m=0.Youmayassumethat0 OutputForeachcase,printthecasenumberaswellasthenumberofpairs(a,b)satisfyingthegivenproperty.Printtheoutputforeachcaseononelineintheformatasshownbelow. SampleInput110120330400 SampleOutputCase1:2Case2:4Case3:5#includevoidmain(){intN;while(scanf("%d",&N)!=EOF){intkey;for(key=0;key{intn,m,x=0;while(scanf("%d%d",&n,&m)!=EOF){inti,j,count=0;if(n==0&&m==0)break;for(i=1;i{for(j=i+1;j{if((i*i+j*j+m)%(i*j)==0){count++;}}}printf("Case%d:%d\n",++x,count);}if(key!=N-1){printf("\n");}}} } 杭电1019LeastCommonMultipleTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):17599 AcceptedSubmission(s):6554 ProblemDescriptionTheleastcommonmultiple(LCM)ofasetofpositiveintegersisthesmallestpositiveintegerwhichisdivisiblebyallthenumbersintheset.Forexample,theLCMof5,7and15is105. InputInputwillconsistofmultipleprobleminstances.Thefirstlineoftheinputwillcontainasingleintegerindicatingthenumberofprobleminstances.Eachinstancewillconsistofasinglelineoftheformmn1n2n3...nmwheremisthenumberofintegersinthesetandn1...nmaretheintegers.Allintegerswillbepositiveandliewithintherangeofa32-bitinteger. OutputForeachprobleminstance,outputasinglelinecontainingthecorrespondingLCM.Allresultswilllieintherangeofa32-bitinteger. SampleInput235715641029693612877921 SampleOutput10510296 SourceEastCentralNorthAmerica2003,Practice #includeintLCM(intm,intn){intlcm,s,r,t,mm,nn;mm=m;nn=n;if(m{t=m;m=n;n=t;}while(n!=0){r=m%n;m=n;n=r;}lcm=mm/m*nn;returnlcm;}intmain(){intt;intnum[1000];inti,n;while(scanf("%d",&t)!=EOF){while(t--){scanf("%d",&n);for(i=0;i{scanf("%d",&num[i]);}for(i=0;i{num[i+1]=LCM(num[i],num[i+1]);}printf("%d\n",num[i]);}}return0;}杭电1020EncodingTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):17004 AcceptedSubmission(s):7270 ProblemDescriptionGivenastringcontainingonly'A'-'Z',wecouldencodeitusingthefollowingmethod: 1.Eachsub-stringcontainingksamecharactersshouldbeencodedto"kX"where"X"istheonlycharacterinthissub-string.2.Ifthelengthofthesub-stringis1,'1'shouldbeignored. InputThefirstlinecontainsanintegerN(1<=N<=100)whichindicatesthenumberoftestcases.ThenextNlinescontainNstrings.Eachstringconsistsofonly'A'-'Z'andthelengthislessthan10000. OutputForeachtestcase,outputtheencodedstringinaline. SampleInput2ABCABBCCC SampleOutputABCA2B3C #includevoidmain(){intn;chara[10000];while(scanf("%d",&n)!=EOF){inti;getchar();while(n--){gets(a);for(i=0;a[i]!='\0';i++){inttemp=1;while(a[i]==a[i+1]){temp++;i++;}if(temp==1)printf("%c",a[i]);elseprintf("%d%c",temp,a[i]);}printf("\n");}}}杭电1166敌兵布阵TimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):20003 AcceptedSubmission(s):8757 ProblemDescriptionC国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人数都有可能发生变动,可能增加或减少若干人手,但这些都逃不过C国的监视。中央情报局要研究敌人究竟演习什么战术,所以Tidy要随时向Derek汇报某一段连续的工兵营地一共有多少人,例如Derek问:“Tidy,马上汇报第3个营地到第10个营地共有多少人!”Tidy就要马上开始计算这一段的总人数并汇报。但敌兵营地的人数经常变动,而Derek每次询问的段都不一样,所以Tidy不得不每次都一个一个营地的去数,很快就精疲力尽了,Derek对Tidy的计算速度越来越不满:"你个死肥仔,算得这么慢,我炒你鱿鱼!”Tidy想:“你自己来算算看,这可真是一项累人的工作!我恨不得你炒我鱿鱼呢!”无奈之下,Tidy只好打电话向计算机专家Windbreaker求救,Windbreaker说:“死肥仔,叫你平时做多点acm题和看多点算法书,现在尝到苦果了吧!”Tidy说:"我知错了。。。"但Windbreaker已经挂掉电话了。Tidy很苦恼,这么算他真的会崩溃的,聪明的读者,你能写个程序帮他完成这项工作吗?不过如果你的程序效率不够高的话,Tidy还是会受到Derek的责骂的. Input第一行一个整数T,表示有T组数据。每组数据第一行一个正整数N(N<=50000),表示敌人有N个工兵营地,接下来有N个正整数,第i个正整数ai代表第i个工兵营地里开始时有ai个人(1<=ai<=50)。接下来每行有一条命令,命令有4种形式:(1)Addij,i和j为正整数,表示第i个营地增加j个人(j不超过30)(2)Subij,i和j为正整数,表示第i个营地减少j个人(j不超过30);(3)Queryij,i和j为正整数,i<=j,表示询问第i到第j个营地的总人数;(4)End表示结束,这条命令在每组数据最后出现;每组数据最多有40000条命令 Output对第i组数据,首先输出“Casei:”和回车,对于每个Query询问,输出一个整数并回车,表示询问的段中的总人数,这个数保持在int以内。 SampleInput11012345678910Query13Add36Query27Sub102Add63Query310End SampleOutputCase1:63359(线段树)#include#include#defineMAX50010intnum[MAX];typedefstructnode{intlchild;intrchild;intnumber;};nodea[4*MAX];intbulit(ints,intt,intstep){intk,mid,x,y;if(s==t){a[step].
if(i==j)
continue;
for(k=0;kif(k==i||k==j)continue;for(l=0;lif(l==k||l==i||l==j)continue;for(m=0;mif(m==l||m==k||m==j||l==i)continue;taget=get_taget(key[i],key[j],key[k],key[l],key[m]);if(taget==data){f=1;key[i]=key[i]+64;key[j]=key[j]+64;key[k]=key[k]+64;key[l]=key[l]+64;key[m]=key[m]+64;printf("%c%c%c%c%c\n",key[i],key[j],key[k],key[l],key[m]);}}}}}}if(f==0)printf("nosolution\n");}return0;} 杭电1017:AMathematicalCuriosityTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):16821 AcceptedSubmission(s):5238 ProblemDescriptionGiventwointegersnandm,countthenumberofpairsofintegers(a,b)suchthat0Thisproblemcontainsmultipletestcases!ThefirstlineofamultipleinputisanintegerN,thenablanklinefollowedbyNinputblocks.Eachinputblockisintheformatindicatedintheproblemdescription.Thereisablanklinebetweeninputblocks.TheoutputformatconsistsofNoutputblocks.Thereisablanklinebetweenoutputblocks. InputYouwillbegivenanumberofcasesintheinput.Eachcaseisspecifiedbyalinecontainingtheintegersnandm.Theendofinputisindicatedbyacaseinwhichn=m=0.Youmayassumethat0 OutputForeachcase,printthecasenumberaswellasthenumberofpairs(a,b)satisfyingthegivenproperty.Printtheoutputforeachcaseononelineintheformatasshownbelow. SampleInput110120330400 SampleOutputCase1:2Case2:4Case3:5#includevoidmain(){intN;while(scanf("%d",&N)!=EOF){intkey;for(key=0;key{intn,m,x=0;while(scanf("%d%d",&n,&m)!=EOF){inti,j,count=0;if(n==0&&m==0)break;for(i=1;i{for(j=i+1;j{if((i*i+j*j+m)%(i*j)==0){count++;}}}printf("Case%d:%d\n",++x,count);}if(key!=N-1){printf("\n");}}} } 杭电1019LeastCommonMultipleTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):17599 AcceptedSubmission(s):6554 ProblemDescriptionTheleastcommonmultiple(LCM)ofasetofpositiveintegersisthesmallestpositiveintegerwhichisdivisiblebyallthenumbersintheset.Forexample,theLCMof5,7and15is105. InputInputwillconsistofmultipleprobleminstances.Thefirstlineoftheinputwillcontainasingleintegerindicatingthenumberofprobleminstances.Eachinstancewillconsistofasinglelineoftheformmn1n2n3...nmwheremisthenumberofintegersinthesetandn1...nmaretheintegers.Allintegerswillbepositiveandliewithintherangeofa32-bitinteger. OutputForeachprobleminstance,outputasinglelinecontainingthecorrespondingLCM.Allresultswilllieintherangeofa32-bitinteger. SampleInput235715641029693612877921 SampleOutput10510296 SourceEastCentralNorthAmerica2003,Practice #includeintLCM(intm,intn){intlcm,s,r,t,mm,nn;mm=m;nn=n;if(m{t=m;m=n;n=t;}while(n!=0){r=m%n;m=n;n=r;}lcm=mm/m*nn;returnlcm;}intmain(){intt;intnum[1000];inti,n;while(scanf("%d",&t)!=EOF){while(t--){scanf("%d",&n);for(i=0;i{scanf("%d",&num[i]);}for(i=0;i{num[i+1]=LCM(num[i],num[i+1]);}printf("%d\n",num[i]);}}return0;}杭电1020EncodingTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):17004 AcceptedSubmission(s):7270 ProblemDescriptionGivenastringcontainingonly'A'-'Z',wecouldencodeitusingthefollowingmethod: 1.Eachsub-stringcontainingksamecharactersshouldbeencodedto"kX"where"X"istheonlycharacterinthissub-string.2.Ifthelengthofthesub-stringis1,'1'shouldbeignored. InputThefirstlinecontainsanintegerN(1<=N<=100)whichindicatesthenumberoftestcases.ThenextNlinescontainNstrings.Eachstringconsistsofonly'A'-'Z'andthelengthislessthan10000. OutputForeachtestcase,outputtheencodedstringinaline. SampleInput2ABCABBCCC SampleOutputABCA2B3C #includevoidmain(){intn;chara[10000];while(scanf("%d",&n)!=EOF){inti;getchar();while(n--){gets(a);for(i=0;a[i]!='\0';i++){inttemp=1;while(a[i]==a[i+1]){temp++;i++;}if(temp==1)printf("%c",a[i]);elseprintf("%d%c",temp,a[i]);}printf("\n");}}}杭电1166敌兵布阵TimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):20003 AcceptedSubmission(s):8757 ProblemDescriptionC国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人数都有可能发生变动,可能增加或减少若干人手,但这些都逃不过C国的监视。中央情报局要研究敌人究竟演习什么战术,所以Tidy要随时向Derek汇报某一段连续的工兵营地一共有多少人,例如Derek问:“Tidy,马上汇报第3个营地到第10个营地共有多少人!”Tidy就要马上开始计算这一段的总人数并汇报。但敌兵营地的人数经常变动,而Derek每次询问的段都不一样,所以Tidy不得不每次都一个一个营地的去数,很快就精疲力尽了,Derek对Tidy的计算速度越来越不满:"你个死肥仔,算得这么慢,我炒你鱿鱼!”Tidy想:“你自己来算算看,这可真是一项累人的工作!我恨不得你炒我鱿鱼呢!”无奈之下,Tidy只好打电话向计算机专家Windbreaker求救,Windbreaker说:“死肥仔,叫你平时做多点acm题和看多点算法书,现在尝到苦果了吧!”Tidy说:"我知错了。。。"但Windbreaker已经挂掉电话了。Tidy很苦恼,这么算他真的会崩溃的,聪明的读者,你能写个程序帮他完成这项工作吗?不过如果你的程序效率不够高的话,Tidy还是会受到Derek的责骂的. Input第一行一个整数T,表示有T组数据。每组数据第一行一个正整数N(N<=50000),表示敌人有N个工兵营地,接下来有N个正整数,第i个正整数ai代表第i个工兵营地里开始时有ai个人(1<=ai<=50)。接下来每行有一条命令,命令有4种形式:(1)Addij,i和j为正整数,表示第i个营地增加j个人(j不超过30)(2)Subij,i和j为正整数,表示第i个营地减少j个人(j不超过30);(3)Queryij,i和j为正整数,i<=j,表示询问第i到第j个营地的总人数;(4)End表示结束,这条命令在每组数据最后出现;每组数据最多有40000条命令 Output对第i组数据,首先输出“Casei:”和回车,对于每个Query询问,输出一个整数并回车,表示询问的段中的总人数,这个数保持在int以内。 SampleInput11012345678910Query13Add36Query27Sub102Add63Query310End SampleOutputCase1:63359(线段树)#include#include#defineMAX50010intnum[MAX];typedefstructnode{intlchild;intrchild;intnumber;};nodea[4*MAX];intbulit(ints,intt,intstep){intk,mid,x,y;if(s==t){a[step].
if(k==i||k==j)
for(l=0;lif(l==k||l==i||l==j)continue;for(m=0;mif(m==l||m==k||m==j||l==i)continue;taget=get_taget(key[i],key[j],key[k],key[l],key[m]);if(taget==data){f=1;key[i]=key[i]+64;key[j]=key[j]+64;key[k]=key[k]+64;key[l]=key[l]+64;key[m]=key[m]+64;printf("%c%c%c%c%c\n",key[i],key[j],key[k],key[l],key[m]);}}}}}}if(f==0)printf("nosolution\n");}return0;} 杭电1017:AMathematicalCuriosityTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):16821 AcceptedSubmission(s):5238 ProblemDescriptionGiventwointegersnandm,countthenumberofpairsofintegers(a,b)suchthat0Thisproblemcontainsmultipletestcases!ThefirstlineofamultipleinputisanintegerN,thenablanklinefollowedbyNinputblocks.Eachinputblockisintheformatindicatedintheproblemdescription.Thereisablanklinebetweeninputblocks.TheoutputformatconsistsofNoutputblocks.Thereisablanklinebetweenoutputblocks. InputYouwillbegivenanumberofcasesintheinput.Eachcaseisspecifiedbyalinecontainingtheintegersnandm.Theendofinputisindicatedbyacaseinwhichn=m=0.Youmayassumethat0 OutputForeachcase,printthecasenumberaswellasthenumberofpairs(a,b)satisfyingthegivenproperty.Printtheoutputforeachcaseononelineintheformatasshownbelow. SampleInput110120330400 SampleOutputCase1:2Case2:4Case3:5#includevoidmain(){intN;while(scanf("%d",&N)!=EOF){intkey;for(key=0;key{intn,m,x=0;while(scanf("%d%d",&n,&m)!=EOF){inti,j,count=0;if(n==0&&m==0)break;for(i=1;i{for(j=i+1;j{if((i*i+j*j+m)%(i*j)==0){count++;}}}printf("Case%d:%d\n",++x,count);}if(key!=N-1){printf("\n");}}} } 杭电1019LeastCommonMultipleTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):17599 AcceptedSubmission(s):6554 ProblemDescriptionTheleastcommonmultiple(LCM)ofasetofpositiveintegersisthesmallestpositiveintegerwhichisdivisiblebyallthenumbersintheset.Forexample,theLCMof5,7and15is105. InputInputwillconsistofmultipleprobleminstances.Thefirstlineoftheinputwillcontainasingleintegerindicatingthenumberofprobleminstances.Eachinstancewillconsistofasinglelineoftheformmn1n2n3...nmwheremisthenumberofintegersinthesetandn1...nmaretheintegers.Allintegerswillbepositiveandliewithintherangeofa32-bitinteger. OutputForeachprobleminstance,outputasinglelinecontainingthecorrespondingLCM.Allresultswilllieintherangeofa32-bitinteger. SampleInput235715641029693612877921 SampleOutput10510296 SourceEastCentralNorthAmerica2003,Practice #includeintLCM(intm,intn){intlcm,s,r,t,mm,nn;mm=m;nn=n;if(m{t=m;m=n;n=t;}while(n!=0){r=m%n;m=n;n=r;}lcm=mm/m*nn;returnlcm;}intmain(){intt;intnum[1000];inti,n;while(scanf("%d",&t)!=EOF){while(t--){scanf("%d",&n);for(i=0;i{scanf("%d",&num[i]);}for(i=0;i{num[i+1]=LCM(num[i],num[i+1]);}printf("%d\n",num[i]);}}return0;}杭电1020EncodingTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):17004 AcceptedSubmission(s):7270 ProblemDescriptionGivenastringcontainingonly'A'-'Z',wecouldencodeitusingthefollowingmethod: 1.Eachsub-stringcontainingksamecharactersshouldbeencodedto"kX"where"X"istheonlycharacterinthissub-string.2.Ifthelengthofthesub-stringis1,'1'shouldbeignored. InputThefirstlinecontainsanintegerN(1<=N<=100)whichindicatesthenumberoftestcases.ThenextNlinescontainNstrings.Eachstringconsistsofonly'A'-'Z'andthelengthislessthan10000. OutputForeachtestcase,outputtheencodedstringinaline. SampleInput2ABCABBCCC SampleOutputABCA2B3C #includevoidmain(){intn;chara[10000];while(scanf("%d",&n)!=EOF){inti;getchar();while(n--){gets(a);for(i=0;a[i]!='\0';i++){inttemp=1;while(a[i]==a[i+1]){temp++;i++;}if(temp==1)printf("%c",a[i]);elseprintf("%d%c",temp,a[i]);}printf("\n");}}}杭电1166敌兵布阵TimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):20003 AcceptedSubmission(s):8757 ProblemDescriptionC国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人数都有可能发生变动,可能增加或减少若干人手,但这些都逃不过C国的监视。中央情报局要研究敌人究竟演习什么战术,所以Tidy要随时向Derek汇报某一段连续的工兵营地一共有多少人,例如Derek问:“Tidy,马上汇报第3个营地到第10个营地共有多少人!”Tidy就要马上开始计算这一段的总人数并汇报。但敌兵营地的人数经常变动,而Derek每次询问的段都不一样,所以Tidy不得不每次都一个一个营地的去数,很快就精疲力尽了,Derek对Tidy的计算速度越来越不满:"你个死肥仔,算得这么慢,我炒你鱿鱼!”Tidy想:“你自己来算算看,这可真是一项累人的工作!我恨不得你炒我鱿鱼呢!”无奈之下,Tidy只好打电话向计算机专家Windbreaker求救,Windbreaker说:“死肥仔,叫你平时做多点acm题和看多点算法书,现在尝到苦果了吧!”Tidy说:"我知错了。。。"但Windbreaker已经挂掉电话了。Tidy很苦恼,这么算他真的会崩溃的,聪明的读者,你能写个程序帮他完成这项工作吗?不过如果你的程序效率不够高的话,Tidy还是会受到Derek的责骂的. Input第一行一个整数T,表示有T组数据。每组数据第一行一个正整数N(N<=50000),表示敌人有N个工兵营地,接下来有N个正整数,第i个正整数ai代表第i个工兵营地里开始时有ai个人(1<=ai<=50)。接下来每行有一条命令,命令有4种形式:(1)Addij,i和j为正整数,表示第i个营地增加j个人(j不超过30)(2)Subij,i和j为正整数,表示第i个营地减少j个人(j不超过30);(3)Queryij,i和j为正整数,i<=j,表示询问第i到第j个营地的总人数;(4)End表示结束,这条命令在每组数据最后出现;每组数据最多有40000条命令 Output对第i组数据,首先输出“Casei:”和回车,对于每个Query询问,输出一个整数并回车,表示询问的段中的总人数,这个数保持在int以内。 SampleInput11012345678910Query13Add36Query27Sub102Add63Query310End SampleOutputCase1:63359(线段树)#include#include#defineMAX50010intnum[MAX];typedefstructnode{intlchild;intrchild;intnumber;};nodea[4*MAX];intbulit(ints,intt,intstep){intk,mid,x,y;if(s==t){a[step].
if(l==k||l==i||l==j)
for(m=0;mif(m==l||m==k||m==j||l==i)continue;taget=get_taget(key[i],key[j],key[k],key[l],key[m]);if(taget==data){f=1;key[i]=key[i]+64;key[j]=key[j]+64;key[k]=key[k]+64;key[l]=key[l]+64;key[m]=key[m]+64;printf("%c%c%c%c%c\n",key[i],key[j],key[k],key[l],key[m]);}}}}}}if(f==0)printf("nosolution\n");}return0;} 杭电1017:AMathematicalCuriosityTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):16821 AcceptedSubmission(s):5238 ProblemDescriptionGiventwointegersnandm,countthenumberofpairsofintegers(a,b)suchthat0Thisproblemcontainsmultipletestcases!ThefirstlineofamultipleinputisanintegerN,thenablanklinefollowedbyNinputblocks.Eachinputblockisintheformatindicatedintheproblemdescription.Thereisablanklinebetweeninputblocks.TheoutputformatconsistsofNoutputblocks.Thereisablanklinebetweenoutputblocks. InputYouwillbegivenanumberofcasesintheinput.Eachcaseisspecifiedbyalinecontainingtheintegersnandm.Theendofinputisindicatedbyacaseinwhichn=m=0.Youmayassumethat0 OutputForeachcase,printthecasenumberaswellasthenumberofpairs(a,b)satisfyingthegivenproperty.Printtheoutputforeachcaseononelineintheformatasshownbelow. SampleInput110120330400 SampleOutputCase1:2Case2:4Case3:5#includevoidmain(){intN;while(scanf("%d",&N)!=EOF){intkey;for(key=0;key{intn,m,x=0;while(scanf("%d%d",&n,&m)!=EOF){inti,j,count=0;if(n==0&&m==0)break;for(i=1;i{for(j=i+1;j{if((i*i+j*j+m)%(i*j)==0){count++;}}}printf("Case%d:%d\n",++x,count);}if(key!=N-1){printf("\n");}}} } 杭电1019LeastCommonMultipleTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):17599 AcceptedSubmission(s):6554 ProblemDescriptionTheleastcommonmultiple(LCM)ofasetofpositiveintegersisthesmallestpositiveintegerwhichisdivisiblebyallthenumbersintheset.Forexample,theLCMof5,7and15is105. InputInputwillconsistofmultipleprobleminstances.Thefirstlineoftheinputwillcontainasingleintegerindicatingthenumberofprobleminstances.Eachinstancewillconsistofasinglelineoftheformmn1n2n3...nmwheremisthenumberofintegersinthesetandn1...nmaretheintegers.Allintegerswillbepositiveandliewithintherangeofa32-bitinteger. OutputForeachprobleminstance,outputasinglelinecontainingthecorrespondingLCM.Allresultswilllieintherangeofa32-bitinteger. SampleInput235715641029693612877921 SampleOutput10510296 SourceEastCentralNorthAmerica2003,Practice #includeintLCM(intm,intn){intlcm,s,r,t,mm,nn;mm=m;nn=n;if(m{t=m;m=n;n=t;}while(n!=0){r=m%n;m=n;n=r;}lcm=mm/m*nn;returnlcm;}intmain(){intt;intnum[1000];inti,n;while(scanf("%d",&t)!=EOF){while(t--){scanf("%d",&n);for(i=0;i{scanf("%d",&num[i]);}for(i=0;i{num[i+1]=LCM(num[i],num[i+1]);}printf("%d\n",num[i]);}}return0;}杭电1020EncodingTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):17004 AcceptedSubmission(s):7270 ProblemDescriptionGivenastringcontainingonly'A'-'Z',wecouldencodeitusingthefollowingmethod: 1.Eachsub-stringcontainingksamecharactersshouldbeencodedto"kX"where"X"istheonlycharacterinthissub-string.2.Ifthelengthofthesub-stringis1,'1'shouldbeignored. InputThefirstlinecontainsanintegerN(1<=N<=100)whichindicatesthenumberoftestcases.ThenextNlinescontainNstrings.Eachstringconsistsofonly'A'-'Z'andthelengthislessthan10000. OutputForeachtestcase,outputtheencodedstringinaline. SampleInput2ABCABBCCC SampleOutputABCA2B3C #includevoidmain(){intn;chara[10000];while(scanf("%d",&n)!=EOF){inti;getchar();while(n--){gets(a);for(i=0;a[i]!='\0';i++){inttemp=1;while(a[i]==a[i+1]){temp++;i++;}if(temp==1)printf("%c",a[i]);elseprintf("%d%c",temp,a[i]);}printf("\n");}}}杭电1166敌兵布阵TimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):20003 AcceptedSubmission(s):8757 ProblemDescriptionC国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人数都有可能发生变动,可能增加或减少若干人手,但这些都逃不过C国的监视。中央情报局要研究敌人究竟演习什么战术,所以Tidy要随时向Derek汇报某一段连续的工兵营地一共有多少人,例如Derek问:“Tidy,马上汇报第3个营地到第10个营地共有多少人!”Tidy就要马上开始计算这一段的总人数并汇报。但敌兵营地的人数经常变动,而Derek每次询问的段都不一样,所以Tidy不得不每次都一个一个营地的去数,很快就精疲力尽了,Derek对Tidy的计算速度越来越不满:"你个死肥仔,算得这么慢,我炒你鱿鱼!”Tidy想:“你自己来算算看,这可真是一项累人的工作!我恨不得你炒我鱿鱼呢!”无奈之下,Tidy只好打电话向计算机专家Windbreaker求救,Windbreaker说:“死肥仔,叫你平时做多点acm题和看多点算法书,现在尝到苦果了吧!”Tidy说:"我知错了。。。"但Windbreaker已经挂掉电话了。Tidy很苦恼,这么算他真的会崩溃的,聪明的读者,你能写个程序帮他完成这项工作吗?不过如果你的程序效率不够高的话,Tidy还是会受到Derek的责骂的. Input第一行一个整数T,表示有T组数据。每组数据第一行一个正整数N(N<=50000),表示敌人有N个工兵营地,接下来有N个正整数,第i个正整数ai代表第i个工兵营地里开始时有ai个人(1<=ai<=50)。接下来每行有一条命令,命令有4种形式:(1)Addij,i和j为正整数,表示第i个营地增加j个人(j不超过30)(2)Subij,i和j为正整数,表示第i个营地减少j个人(j不超过30);(3)Queryij,i和j为正整数,i<=j,表示询问第i到第j个营地的总人数;(4)End表示结束,这条命令在每组数据最后出现;每组数据最多有40000条命令 Output对第i组数据,首先输出“Casei:”和回车,对于每个Query询问,输出一个整数并回车,表示询问的段中的总人数,这个数保持在int以内。 SampleInput11012345678910Query13Add36Query27Sub102Add63Query310End SampleOutputCase1:63359(线段树)#include#include#defineMAX50010intnum[MAX];typedefstructnode{intlchild;intrchild;intnumber;};nodea[4*MAX];intbulit(ints,intt,intstep){intk,mid,x,y;if(s==t){a[step].
if(m==l||m==k||m==j||l==i)
taget=get_taget(key[i],key[j],key[k],key[l],key[m]);
if(taget==data){
f=1;
key[i]=key[i]+64;
key[j]=key[j]+64;
key[k]=key[k]+64;
key[l]=key[l]+64;
key[m]=key[m]+64;
printf("%c%c%c%c%c\n",key[i],key[j],key[k],key[l],key[m]);
if(f==0)
printf("nosolution\n");
return0;
杭电1017:
AMathematicalCuriosity
16821 AcceptedSubmission(s):
5238
Giventwointegersnandm,countthenumberofpairsofintegers(a,b)suchthat0Thisproblemcontainsmultipletestcases!ThefirstlineofamultipleinputisanintegerN,thenablanklinefollowedbyNinputblocks.Eachinputblockisintheformatindicatedintheproblemdescription.Thereisablanklinebetweeninputblocks.TheoutputformatconsistsofNoutputblocks.Thereisablanklinebetweenoutputblocks. InputYouwillbegivenanumberofcasesintheinput.Eachcaseisspecifiedbyalinecontainingtheintegersnandm.Theendofinputisindicatedbyacaseinwhichn=m=0.Youmayassumethat0 OutputForeachcase,printthecasenumberaswellasthenumberofpairs(a,b)satisfyingthegivenproperty.Printtheoutputforeachcaseononelineintheformatasshownbelow. SampleInput110120330400 SampleOutputCase1:2Case2:4Case3:5#includevoidmain(){intN;while(scanf("%d",&N)!=EOF){intkey;for(key=0;key{intn,m,x=0;while(scanf("%d%d",&n,&m)!=EOF){inti,j,count=0;if(n==0&&m==0)break;for(i=1;i{for(j=i+1;j{if((i*i+j*j+m)%(i*j)==0){count++;}}}printf("Case%d:%d\n",++x,count);}if(key!=N-1){printf("\n");}}} } 杭电1019LeastCommonMultipleTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):17599 AcceptedSubmission(s):6554 ProblemDescriptionTheleastcommonmultiple(LCM)ofasetofpositiveintegersisthesmallestpositiveintegerwhichisdivisiblebyallthenumbersintheset.Forexample,theLCMof5,7and15is105. InputInputwillconsistofmultipleprobleminstances.Thefirstlineoftheinputwillcontainasingleintegerindicatingthenumberofprobleminstances.Eachinstancewillconsistofasinglelineoftheformmn1n2n3...nmwheremisthenumberofintegersinthesetandn1...nmaretheintegers.Allintegerswillbepositiveandliewithintherangeofa32-bitinteger. OutputForeachprobleminstance,outputasinglelinecontainingthecorrespondingLCM.Allresultswilllieintherangeofa32-bitinteger. SampleInput235715641029693612877921 SampleOutput10510296 SourceEastCentralNorthAmerica2003,Practice #includeintLCM(intm,intn){intlcm,s,r,t,mm,nn;mm=m;nn=n;if(m{t=m;m=n;n=t;}while(n!=0){r=m%n;m=n;n=r;}lcm=mm/m*nn;returnlcm;}intmain(){intt;intnum[1000];inti,n;while(scanf("%d",&t)!=EOF){while(t--){scanf("%d",&n);for(i=0;i{scanf("%d",&num[i]);}for(i=0;i{num[i+1]=LCM(num[i],num[i+1]);}printf("%d\n",num[i]);}}return0;}杭电1020EncodingTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):17004 AcceptedSubmission(s):7270 ProblemDescriptionGivenastringcontainingonly'A'-'Z',wecouldencodeitusingthefollowingmethod: 1.Eachsub-stringcontainingksamecharactersshouldbeencodedto"kX"where"X"istheonlycharacterinthissub-string.2.Ifthelengthofthesub-stringis1,'1'shouldbeignored. InputThefirstlinecontainsanintegerN(1<=N<=100)whichindicatesthenumberoftestcases.ThenextNlinescontainNstrings.Eachstringconsistsofonly'A'-'Z'andthelengthislessthan10000. OutputForeachtestcase,outputtheencodedstringinaline. SampleInput2ABCABBCCC SampleOutputABCA2B3C #includevoidmain(){intn;chara[10000];while(scanf("%d",&n)!=EOF){inti;getchar();while(n--){gets(a);for(i=0;a[i]!='\0';i++){inttemp=1;while(a[i]==a[i+1]){temp++;i++;}if(temp==1)printf("%c",a[i]);elseprintf("%d%c",temp,a[i]);}printf("\n");}}}杭电1166敌兵布阵TimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):20003 AcceptedSubmission(s):8757 ProblemDescriptionC国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人数都有可能发生变动,可能增加或减少若干人手,但这些都逃不过C国的监视。中央情报局要研究敌人究竟演习什么战术,所以Tidy要随时向Derek汇报某一段连续的工兵营地一共有多少人,例如Derek问:“Tidy,马上汇报第3个营地到第10个营地共有多少人!”Tidy就要马上开始计算这一段的总人数并汇报。但敌兵营地的人数经常变动,而Derek每次询问的段都不一样,所以Tidy不得不每次都一个一个营地的去数,很快就精疲力尽了,Derek对Tidy的计算速度越来越不满:"你个死肥仔,算得这么慢,我炒你鱿鱼!”Tidy想:“你自己来算算看,这可真是一项累人的工作!我恨不得你炒我鱿鱼呢!”无奈之下,Tidy只好打电话向计算机专家Windbreaker求救,Windbreaker说:“死肥仔,叫你平时做多点acm题和看多点算法书,现在尝到苦果了吧!”Tidy说:"我知错了。。。"但Windbreaker已经挂掉电话了。Tidy很苦恼,这么算他真的会崩溃的,聪明的读者,你能写个程序帮他完成这项工作吗?不过如果你的程序效率不够高的话,Tidy还是会受到Derek的责骂的. Input第一行一个整数T,表示有T组数据。每组数据第一行一个正整数N(N<=50000),表示敌人有N个工兵营地,接下来有N个正整数,第i个正整数ai代表第i个工兵营地里开始时有ai个人(1<=ai<=50)。接下来每行有一条命令,命令有4种形式:(1)Addij,i和j为正整数,表示第i个营地增加j个人(j不超过30)(2)Subij,i和j为正整数,表示第i个营地减少j个人(j不超过30);(3)Queryij,i和j为正整数,i<=j,表示询问第i到第j个营地的总人数;(4)End表示结束,这条命令在每组数据最后出现;每组数据最多有40000条命令 Output对第i组数据,首先输出“Casei:”和回车,对于每个Query询问,输出一个整数并回车,表示询问的段中的总人数,这个数保持在int以内。 SampleInput11012345678910Query13Add36Query27Sub102Add63Query310End SampleOutputCase1:63359(线段树)#include#include#defineMAX50010intnum[MAX];typedefstructnode{intlchild;intrchild;intnumber;};nodea[4*MAX];intbulit(ints,intt,intstep){intk,mid,x,y;if(s==t){a[step].
Thisproblemcontainsmultipletestcases!
ThefirstlineofamultipleinputisanintegerN,thenablanklinefollowedbyNinputblocks.Eachinputblockisintheformatindicatedintheproblemdescription.Thereisablanklinebetweeninputblocks.
TheoutputformatconsistsofNoutputblocks.Thereisablanklinebetweenoutputblocks.
Input
Youwillbegivenanumberofcasesintheinput.Eachcaseisspecifiedbyalinecontainingtheintegersnandm.Theendofinputisindicatedbyacaseinwhichn=m=0.Youmayassumethat0 OutputForeachcase,printthecasenumberaswellasthenumberofpairs(a,b)satisfyingthegivenproperty.Printtheoutputforeachcaseononelineintheformatasshownbelow. SampleInput110120330400 SampleOutputCase1:2Case2:4Case3:5#includevoidmain(){intN;while(scanf("%d",&N)!=EOF){intkey;for(key=0;key{intn,m,x=0;while(scanf("%d%d",&n,&m)!=EOF){inti,j,count=0;if(n==0&&m==0)break;for(i=1;i{for(j=i+1;j{if((i*i+j*j+m)%(i*j)==0){count++;}}}printf("Case%d:%d\n",++x,count);}if(key!=N-1){printf("\n");}}} } 杭电1019LeastCommonMultipleTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):17599 AcceptedSubmission(s):6554 ProblemDescriptionTheleastcommonmultiple(LCM)ofasetofpositiveintegersisthesmallestpositiveintegerwhichisdivisiblebyallthenumbersintheset.Forexample,theLCMof5,7and15is105. InputInputwillconsistofmultipleprobleminstances.Thefirstlineoftheinputwillcontainasingleintegerindicatingthenumberofprobleminstances.Eachinstancewillconsistofasinglelineoftheformmn1n2n3...nmwheremisthenumberofintegersinthesetandn1...nmaretheintegers.Allintegerswillbepositiveandliewithintherangeofa32-bitinteger. OutputForeachprobleminstance,outputasinglelinecontainingthecorrespondingLCM.Allresultswilllieintherangeofa32-bitinteger. SampleInput235715641029693612877921 SampleOutput10510296 SourceEastCentralNorthAmerica2003,Practice #includeintLCM(intm,intn){intlcm,s,r,t,mm,nn;mm=m;nn=n;if(m{t=m;m=n;n=t;}while(n!=0){r=m%n;m=n;n=r;}lcm=mm/m*nn;returnlcm;}intmain(){intt;intnum[1000];inti,n;while(scanf("%d",&t)!=EOF){while(t--){scanf("%d",&n);for(i=0;i{scanf("%d",&num[i]);}for(i=0;i{num[i+1]=LCM(num[i],num[i+1]);}printf("%d\n",num[i]);}}return0;}杭电1020EncodingTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):17004 AcceptedSubmission(s):7270 ProblemDescriptionGivenastringcontainingonly'A'-'Z',wecouldencodeitusingthefollowingmethod: 1.Eachsub-stringcontainingksamecharactersshouldbeencodedto"kX"where"X"istheonlycharacterinthissub-string.2.Ifthelengthofthesub-stringis1,'1'shouldbeignored. InputThefirstlinecontainsanintegerN(1<=N<=100)whichindicatesthenumberoftestcases.ThenextNlinescontainNstrings.Eachstringconsistsofonly'A'-'Z'andthelengthislessthan10000. OutputForeachtestcase,outputtheencodedstringinaline. SampleInput2ABCABBCCC SampleOutputABCA2B3C #includevoidmain(){intn;chara[10000];while(scanf("%d",&n)!=EOF){inti;getchar();while(n--){gets(a);for(i=0;a[i]!='\0';i++){inttemp=1;while(a[i]==a[i+1]){temp++;i++;}if(temp==1)printf("%c",a[i]);elseprintf("%d%c",temp,a[i]);}printf("\n");}}}杭电1166敌兵布阵TimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):20003 AcceptedSubmission(s):8757 ProblemDescriptionC国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人数都有可能发生变动,可能增加或减少若干人手,但这些都逃不过C国的监视。中央情报局要研究敌人究竟演习什么战术,所以Tidy要随时向Derek汇报某一段连续的工兵营地一共有多少人,例如Derek问:“Tidy,马上汇报第3个营地到第10个营地共有多少人!”Tidy就要马上开始计算这一段的总人数并汇报。但敌兵营地的人数经常变动,而Derek每次询问的段都不一样,所以Tidy不得不每次都一个一个营地的去数,很快就精疲力尽了,Derek对Tidy的计算速度越来越不满:"你个死肥仔,算得这么慢,我炒你鱿鱼!”Tidy想:“你自己来算算看,这可真是一项累人的工作!我恨不得你炒我鱿鱼呢!”无奈之下,Tidy只好打电话向计算机专家Windbreaker求救,Windbreaker说:“死肥仔,叫你平时做多点acm题和看多点算法书,现在尝到苦果了吧!”Tidy说:"我知错了。。。"但Windbreaker已经挂掉电话了。Tidy很苦恼,这么算他真的会崩溃的,聪明的读者,你能写个程序帮他完成这项工作吗?不过如果你的程序效率不够高的话,Tidy还是会受到Derek的责骂的. Input第一行一个整数T,表示有T组数据。每组数据第一行一个正整数N(N<=50000),表示敌人有N个工兵营地,接下来有N个正整数,第i个正整数ai代表第i个工兵营地里开始时有ai个人(1<=ai<=50)。接下来每行有一条命令,命令有4种形式:(1)Addij,i和j为正整数,表示第i个营地增加j个人(j不超过30)(2)Subij,i和j为正整数,表示第i个营地减少j个人(j不超过30);(3)Queryij,i和j为正整数,i<=j,表示询问第i到第j个营地的总人数;(4)End表示结束,这条命令在每组数据最后出现;每组数据最多有40000条命令 Output对第i组数据,首先输出“Casei:”和回车,对于每个Query询问,输出一个整数并回车,表示询问的段中的总人数,这个数保持在int以内。 SampleInput11012345678910Query13Add36Query27Sub102Add63Query310End SampleOutputCase1:63359(线段树)#include#include#defineMAX50010intnum[MAX];typedefstructnode{intlchild;intrchild;intnumber;};nodea[4*MAX];intbulit(ints,intt,intstep){intk,mid,x,y;if(s==t){a[step].
Output
Foreachcase,printthecasenumberaswellasthenumberofpairs(a,b)satisfyingthegivenproperty.Printtheoutputforeachcaseononelineintheformatasshownbelow.
1
101
203
304
00
Case1:
2
Case2:
4
Case3:
5
voidmain()
intN;
while(scanf("%d",&N)!
=EOF)
intkey;
for(key=0;key{intn,m,x=0;while(scanf("%d%d",&n,&m)!=EOF){inti,j,count=0;if(n==0&&m==0)break;for(i=1;i{for(j=i+1;j{if((i*i+j*j+m)%(i*j)==0){count++;}}}printf("Case%d:%d\n",++x,count);}if(key!=N-1){printf("\n");}}} } 杭电1019LeastCommonMultipleTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):17599 AcceptedSubmission(s):6554 ProblemDescriptionTheleastcommonmultiple(LCM)ofasetofpositiveintegersisthesmallestpositiveintegerwhichisdivisiblebyallthenumbersintheset.Forexample,theLCMof5,7and15is105. InputInputwillconsistofmultipleprobleminstances.Thefirstlineoftheinputwillcontainasingleintegerindicatingthenumberofprobleminstances.Eachinstancewillconsistofasinglelineoftheformmn1n2n3...nmwheremisthenumberofintegersinthesetandn1...nmaretheintegers.Allintegerswillbepositiveandliewithintherangeofa32-bitinteger. OutputForeachprobleminstance,outputasinglelinecontainingthecorrespondingLCM.Allresultswilllieintherangeofa32-bitinteger. SampleInput235715641029693612877921 SampleOutput10510296 SourceEastCentralNorthAmerica2003,Practice #includeintLCM(intm,intn){intlcm,s,r,t,mm,nn;mm=m;nn=n;if(m{t=m;m=n;n=t;}while(n!=0){r=m%n;m=n;n=r;}lcm=mm/m*nn;returnlcm;}intmain(){intt;intnum[1000];inti,n;while(scanf("%d",&t)!=EOF){while(t--){scanf("%d",&n);for(i=0;i{scanf("%d",&num[i]);}for(i=0;i{num[i+1]=LCM(num[i],num[i+1]);}printf("%d\n",num[i]);}}return0;}杭电1020EncodingTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):17004 AcceptedSubmission(s):7270 ProblemDescriptionGivenastringcontainingonly'A'-'Z',wecouldencodeitusingthefollowingmethod: 1.Eachsub-stringcontainingksamecharactersshouldbeencodedto"kX"where"X"istheonlycharacterinthissub-string.2.Ifthelengthofthesub-stringis1,'1'shouldbeignored. InputThefirstlinecontainsanintegerN(1<=N<=100)whichindicatesthenumberoftestcases.ThenextNlinescontainNstrings.Eachstringconsistsofonly'A'-'Z'andthelengthislessthan10000. OutputForeachtestcase,outputtheencodedstringinaline. SampleInput2ABCABBCCC SampleOutputABCA2B3C #includevoidmain(){intn;chara[10000];while(scanf("%d",&n)!=EOF){inti;getchar();while(n--){gets(a);for(i=0;a[i]!='\0';i++){inttemp=1;while(a[i]==a[i+1]){temp++;i++;}if(temp==1)printf("%c",a[i]);elseprintf("%d%c",temp,a[i]);}printf("\n");}}}杭电1166敌兵布阵TimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):20003 AcceptedSubmission(s):8757 ProblemDescriptionC国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人数都有可能发生变动,可能增加或减少若干人手,但这些都逃不过C国的监视。中央情报局要研究敌人究竟演习什么战术,所以Tidy要随时向Derek汇报某一段连续的工兵营地一共有多少人,例如Derek问:“Tidy,马上汇报第3个营地到第10个营地共有多少人!”Tidy就要马上开始计算这一段的总人数并汇报。但敌兵营地的人数经常变动,而Derek每次询问的段都不一样,所以Tidy不得不每次都一个一个营地的去数,很快就精疲力尽了,Derek对Tidy的计算速度越来越不满:"你个死肥仔,算得这么慢,我炒你鱿鱼!”Tidy想:“你自己来算算看,这可真是一项累人的工作!我恨不得你炒我鱿鱼呢!”无奈之下,Tidy只好打电话向计算机专家Windbreaker求救,Windbreaker说:“死肥仔,叫你平时做多点acm题和看多点算法书,现在尝到苦果了吧!”Tidy说:"我知错了。。。"但Windbreaker已经挂掉电话了。Tidy很苦恼,这么算他真的会崩溃的,聪明的读者,你能写个程序帮他完成这项工作吗?不过如果你的程序效率不够高的话,Tidy还是会受到Derek的责骂的. Input第一行一个整数T,表示有T组数据。每组数据第一行一个正整数N(N<=50000),表示敌人有N个工兵营地,接下来有N个正整数,第i个正整数ai代表第i个工兵营地里开始时有ai个人(1<=ai<=50)。接下来每行有一条命令,命令有4种形式:(1)Addij,i和j为正整数,表示第i个营地增加j个人(j不超过30)(2)Subij,i和j为正整数,表示第i个营地减少j个人(j不超过30);(3)Queryij,i和j为正整数,i<=j,表示询问第i到第j个营地的总人数;(4)End表示结束,这条命令在每组数据最后出现;每组数据最多有40000条命令 Output对第i组数据,首先输出“Casei:”和回车,对于每个Query询问,输出一个整数并回车,表示询问的段中的总人数,这个数保持在int以内。 SampleInput11012345678910Query13Add36Query27Sub102Add63Query310End SampleOutputCase1:63359(线段树)#include#include#defineMAX50010intnum[MAX];typedefstructnode{intlchild;intrchild;intnumber;};nodea[4*MAX];intbulit(ints,intt,intstep){intk,mid,x,y;if(s==t){a[step].
intn,m,x=0;
while(scanf("%d%d",&n,&m)!
inti,j,count=0;
if(n==0&&m==0)
for(i=1;i{for(j=i+1;j{if((i*i+j*j+m)%(i*j)==0){count++;}}}printf("Case%d:%d\n",++x,count);}if(key!=N-1){printf("\n");}}} } 杭电1019LeastCommonMultipleTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):17599 AcceptedSubmission(s):6554 ProblemDescriptionTheleastcommonmultiple(LCM)ofasetofpositiveintegersisthesmallestpositiveintegerwhichisdivisiblebyallthenumbersintheset.Forexample,theLCMof5,7and15is105. InputInputwillconsistofmultipleprobleminstances.Thefirstlineoftheinputwillcontainasingleintegerindicatingthenumberofprobleminstances.Eachinstancewillconsistofasinglelineoftheformmn1n2n3...nmwheremisthenumberofintegersinthesetandn1...nmaretheintegers.Allintegerswillbepositiveandliewithintherangeofa32-bitinteger. OutputForeachprobleminstance,outputasinglelinecontainingthecorrespondingLCM.Allresultswilllieintherangeofa32-bitinteger. SampleInput235715641029693612877921 SampleOutput10510296 SourceEastCentralNorthAmerica2003,Practice #includeintLCM(intm,intn){intlcm,s,r,t,mm,nn;mm=m;nn=n;if(m{t=m;m=n;n=t;}while(n!=0){r=m%n;m=n;n=r;}lcm=mm/m*nn;returnlcm;}intmain(){intt;intnum[1000];inti,n;while(scanf("%d",&t)!=EOF){while(t--){scanf("%d",&n);for(i=0;i{scanf("%d",&num[i]);}for(i=0;i{num[i+1]=LCM(num[i],num[i+1]);}printf("%d\n",num[i]);}}return0;}杭电1020EncodingTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):17004 AcceptedSubmission(s):7270 ProblemDescriptionGivenastringcontainingonly'A'-'Z',wecouldencodeitusingthefollowingmethod: 1.Eachsub-stringcontainingksamecharactersshouldbeencodedto"kX"where"X"istheonlycharacterinthissub-string.2.Ifthelengthofthesub-stringis1,'1'shouldbeignored. InputThefirstlinecontainsanintegerN(1<=N<=100)whichindicatesthenumberoftestcases.ThenextNlinescontainNstrings.Eachstringconsistsofonly'A'-'Z'andthelengthislessthan10000. OutputForeachtestcase,outputtheencodedstringinaline. SampleInput2ABCABBCCC SampleOutputABCA2B3C #includevoidmain(){intn;chara[10000];while(scanf("%d",&n)!=EOF){inti;getchar();while(n--){gets(a);for(i=0;a[i]!='\0';i++){inttemp=1;while(a[i]==a[i+1]){temp++;i++;}if(temp==1)printf("%c",a[i]);elseprintf("%d%c",temp,a[i]);}printf("\n");}}}杭电1166敌兵布阵TimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):20003 AcceptedSubmission(s):8757 ProblemDescriptionC国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人数都有可能发生变动,可能增加或减少若干人手,但这些都逃不过C国的监视。中央情报局要研究敌人究竟演习什么战术,所以Tidy要随时向Derek汇报某一段连续的工兵营地一共有多少人,例如Derek问:“Tidy,马上汇报第3个营地到第10个营地共有多少人!”Tidy就要马上开始计算这一段的总人数并汇报。但敌兵营地的人数经常变动,而Derek每次询问的段都不一样,所以Tidy不得不每次都一个一个营地的去数,很快就精疲力尽了,Derek对Tidy的计算速度越来越不满:"你个死肥仔,算得这么慢,我炒你鱿鱼!”Tidy想:“你自己来算算看,这可真是一项累人的工作!我恨不得你炒我鱿鱼呢!”无奈之下,Tidy只好打电话向计算机专家Windbreaker求救,Windbreaker说:“死肥仔,叫你平时做多点acm题和看多点算法书,现在尝到苦果了吧!”Tidy说:"我知错了。。。"但Windbreaker已经挂掉电话了。Tidy很苦恼,这么算他真的会崩溃的,聪明的读者,你能写个程序帮他完成这项工作吗?不过如果你的程序效率不够高的话,Tidy还是会受到Derek的责骂的. Input第一行一个整数T,表示有T组数据。每组数据第一行一个正整数N(N<=50000),表示敌人有N个工兵营地,接下来有N个正整数,第i个正整数ai代表第i个工兵营地里开始时有ai个人(1<=ai<=50)。接下来每行有一条命令,命令有4种形式:(1)Addij,i和j为正整数,表示第i个营地增加j个人(j不超过30)(2)Subij,i和j为正整数,表示第i个营地减少j个人(j不超过30);(3)Queryij,i和j为正整数,i<=j,表示询问第i到第j个营地的总人数;(4)End表示结束,这条命令在每组数据最后出现;每组数据最多有40000条命令 Output对第i组数据,首先输出“Casei:”和回车,对于每个Query询问,输出一个整数并回车,表示询问的段中的总人数,这个数保持在int以内。 SampleInput11012345678910Query13Add36Query27Sub102Add63Query310End SampleOutputCase1:63359(线段树)#include#include#defineMAX50010intnum[MAX];typedefstructnode{intlchild;intrchild;intnumber;};nodea[4*MAX];intbulit(ints,intt,intstep){intk,mid,x,y;if(s==t){a[step].
for(j=i+1;j{if((i*i+j*j+m)%(i*j)==0){count++;}}}printf("Case%d:%d\n",++x,count);}if(key!=N-1){printf("\n");}}} } 杭电1019LeastCommonMultipleTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):17599 AcceptedSubmission(s):6554 ProblemDescriptionTheleastcommonmultiple(LCM)ofasetofpositiveintegersisthesmallestpositiveintegerwhichisdivisiblebyallthenumbersintheset.Forexample,theLCMof5,7and15is105. InputInputwillconsistofmultipleprobleminstances.Thefirstlineoftheinputwillcontainasingleintegerindicatingthenumberofprobleminstances.Eachinstancewillconsistofasinglelineoftheformmn1n2n3...nmwheremisthenumberofintegersinthesetandn1...nmaretheintegers.Allintegerswillbepositiveandliewithintherangeofa32-bitinteger. OutputForeachprobleminstance,outputasinglelinecontainingthecorrespondingLCM.Allresultswilllieintherangeofa32-bitinteger. SampleInput235715641029693612877921 SampleOutput10510296 SourceEastCentralNorthAmerica2003,Practice #includeintLCM(intm,intn){intlcm,s,r,t,mm,nn;mm=m;nn=n;if(m{t=m;m=n;n=t;}while(n!=0){r=m%n;m=n;n=r;}lcm=mm/m*nn;returnlcm;}intmain(){intt;intnum[1000];inti,n;while(scanf("%d",&t)!=EOF){while(t--){scanf("%d",&n);for(i=0;i{scanf("%d",&num[i]);}for(i=0;i{num[i+1]=LCM(num[i],num[i+1]);}printf("%d\n",num[i]);}}return0;}杭电1020EncodingTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):17004 AcceptedSubmission(s):7270 ProblemDescriptionGivenastringcontainingonly'A'-'Z',wecouldencodeitusingthefollowingmethod: 1.Eachsub-stringcontainingksamecharactersshouldbeencodedto"kX"where"X"istheonlycharacterinthissub-string.2.Ifthelengthofthesub-stringis1,'1'shouldbeignored. InputThefirstlinecontainsanintegerN(1<=N<=100)whichindicatesthenumberoftestcases.ThenextNlinescontainNstrings.Eachstringconsistsofonly'A'-'Z'andthelengthislessthan10000. OutputForeachtestcase,outputtheencodedstringinaline. SampleInput2ABCABBCCC SampleOutputABCA2B3C #includevoidmain(){intn;chara[10000];while(scanf("%d",&n)!=EOF){inti;getchar();while(n--){gets(a);for(i=0;a[i]!='\0';i++){inttemp=1;while(a[i]==a[i+1]){temp++;i++;}if(temp==1)printf("%c",a[i]);elseprintf("%d%c",temp,a[i]);}printf("\n");}}}杭电1166敌兵布阵TimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):20003 AcceptedSubmission(s):8757 ProblemDescriptionC国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人数都有可能发生变动,可能增加或减少若干人手,但这些都逃不过C国的监视。中央情报局要研究敌人究竟演习什么战术,所以Tidy要随时向Derek汇报某一段连续的工兵营地一共有多少人,例如Derek问:“Tidy,马上汇报第3个营地到第10个营地共有多少人!”Tidy就要马上开始计算这一段的总人数并汇报。但敌兵营地的人数经常变动,而Derek每次询问的段都不一样,所以Tidy不得不每次都一个一个营地的去数,很快就精疲力尽了,Derek对Tidy的计算速度越来越不满:"你个死肥仔,算得这么慢,我炒你鱿鱼!”Tidy想:“你自己来算算看,这可真是一项累人的工作!我恨不得你炒我鱿鱼呢!”无奈之下,Tidy只好打电话向计算机专家Windbreaker求救,Windbreaker说:“死肥仔,叫你平时做多点acm题和看多点算法书,现在尝到苦果了吧!”Tidy说:"我知错了。。。"但Windbreaker已经挂掉电话了。Tidy很苦恼,这么算他真的会崩溃的,聪明的读者,你能写个程序帮他完成这项工作吗?不过如果你的程序效率不够高的话,Tidy还是会受到Derek的责骂的. Input第一行一个整数T,表示有T组数据。每组数据第一行一个正整数N(N<=50000),表示敌人有N个工兵营地,接下来有N个正整数,第i个正整数ai代表第i个工兵营地里开始时有ai个人(1<=ai<=50)。接下来每行有一条命令,命令有4种形式:(1)Addij,i和j为正整数,表示第i个营地增加j个人(j不超过30)(2)Subij,i和j为正整数,表示第i个营地减少j个人(j不超过30);(3)Queryij,i和j为正整数,i<=j,表示询问第i到第j个营地的总人数;(4)End表示结束,这条命令在每组数据最后出现;每组数据最多有40000条命令 Output对第i组数据,首先输出“Casei:”和回车,对于每个Query询问,输出一个整数并回车,表示询问的段中的总人数,这个数保持在int以内。 SampleInput11012345678910Query13Add36Query27Sub102Add63Query310End SampleOutputCase1:63359(线段树)#include#include#defineMAX50010intnum[MAX];typedefstructnode{intlchild;intrchild;intnumber;};nodea[4*MAX];intbulit(ints,intt,intstep){intk,mid,x,y;if(s==t){a[step].
if((i*i+j*j+m)%(i*j)==0)
count++;
printf("Case%d:
%d\n",++x,count);
if(key!
=N-1)
printf("\n");
杭电1019
LeastCommonMultiple
17599 AcceptedSubmission(s):
6554
Theleastcommonmultiple(LCM)ofasetofpositiveintegersisthesmallestpositiveintegerwhichisdivisiblebyallthenumbersintheset.Forexample,theLCMof5,7and15is105.
Inputwillconsistofmultipleprobleminstances.Thefirstlineoftheinputwillcontainasingleintegerindicatingthenumberofprobleminstances.Eachinstancewillconsistofasinglelineoftheformmn1n2n3...nmwheremisthenumberofintegersinthesetandn1...nmaretheintegers.Allintegerswillbepositiveandliewithintherangeofa32-bitinteger.
Foreachprobleminstance,outputasinglelinecontainingthecorrespondingLCM.Allresultswilllieintherangeofa32-bitinteger.
35715
641029693612877921
105
10296
Source
EastCentralNorthAmerica2003,Practice
intLCM(intm,intn)
intlcm,s,r,t,mm,nn;
mm=m;
nn=n;
if(m{t=m;m=n;n=t;}while(n!=0){r=m%n;m=n;n=r;}lcm=mm/m*nn;returnlcm;}intmain(){intt;intnum[1000];inti,n;while(scanf("%d",&t)!=EOF){while(t--){scanf("%d",&n);for(i=0;i{scanf("%d",&num[i]);}for(i=0;i{num[i+1]=LCM(num[i],num[i+1]);}printf("%d\n",num[i]);}}return0;}杭电1020EncodingTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):17004 AcceptedSubmission(s):7270 ProblemDescriptionGivenastringcontainingonly'A'-'Z',wecouldencodeitusingthefollowingmethod: 1.Eachsub-stringcontainingksamecharactersshouldbeencodedto"kX"where"X"istheonlycharacterinthissub-string.2.Ifthelengthofthesub-stringis1,'1'shouldbeignored. InputThefirstlinecontainsanintegerN(1<=N<=100)whichindicatesthenumberoftestcases.ThenextNlinescontainNstrings.Eachstringconsistsofonly'A'-'Z'andthelengthislessthan10000. OutputForeachtestcase,outputtheencodedstringinaline. SampleInput2ABCABBCCC SampleOutputABCA2B3C #includevoidmain(){intn;chara[10000];while(scanf("%d",&n)!=EOF){inti;getchar();while(n--){gets(a);for(i=0;a[i]!='\0';i++){inttemp=1;while(a[i]==a[i+1]){temp++;i++;}if(temp==1)printf("%c",a[i]);elseprintf("%d%c",temp,a[i]);}printf("\n");}}}杭电1166敌兵布阵TimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):20003 AcceptedSubmission(s):8757 ProblemDescriptionC国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人数都有可能发生变动,可能增加或减少若干人手,但这些都逃不过C国的监视。中央情报局要研究敌人究竟演习什么战术,所以Tidy要随时向Derek汇报某一段连续的工兵营地一共有多少人,例如Derek问:“Tidy,马上汇报第3个营地到第10个营地共有多少人!”Tidy就要马上开始计算这一段的总人数并汇报。但敌兵营地的人数经常变动,而Derek每次询问的段都不一样,所以Tidy不得不每次都一个一个营地的去数,很快就精疲力尽了,Derek对Tidy的计算速度越来越不满:"你个死肥仔,算得这么慢,我炒你鱿鱼!”Tidy想:“你自己来算算看,这可真是一项累人的工作!我恨不得你炒我鱿鱼呢!”无奈之下,Tidy只好打电话向计算机专家Windbreaker求救,Windbreaker说:“死肥仔,叫你平时做多点acm题和看多点算法书,现在尝到苦果了吧!”Tidy说:"我知错了。。。"但Windbreaker已经挂掉电话了。Tidy很苦恼,这么算他真的会崩溃的,聪明的读者,你能写个程序帮他完成这项工作吗?不过如果你的程序效率不够高的话,Tidy还是会受到Derek的责骂的. Input第一行一个整数T,表示有T组数据。每组数据第一行一个正整数N(N<=50000),表示敌人有N个工兵营地,接下来有N个正整数,第i个正整数ai代表第i个工兵营地里开始时有ai个人(1<=ai<=50)。接下来每行有一条命令,命令有4种形式:(1)Addij,i和j为正整数,表示第i个营地增加j个人(j不超过30)(2)Subij,i和j为正整数,表示第i个营地减少j个人(j不超过30);(3)Queryij,i和j为正整数,i<=j,表示询问第i到第j个营地的总人数;(4)End表示结束,这条命令在每组数据最后出现;每组数据最多有40000条命令 Output对第i组数据,首先输出“Casei:”和回车,对于每个Query询问,输出一个整数并回车,表示询问的段中的总人数,这个数保持在int以内。 SampleInput11012345678910Query13Add36Query27Sub102Add63Query310End SampleOutputCase1:63359(线段树)#include#include#defineMAX50010intnum[MAX];typedefstructnode{intlchild;intrchild;intnumber;};nodea[4*MAX];intbulit(ints,intt,intstep){intk,mid,x,y;if(s==t){a[step].
t=m;
m=n;
n=t;
while(n!
=0)
r=m%n;
n=r;
lcm=mm/m*nn;
returnlcm;
intmain()
intt;
intnum[1000];
inti,n;
while(scanf("%d",&t)!
while(t--)
scanf("%d",&n);
for(i=0;i{scanf("%d",&num[i]);}for(i=0;i{num[i+1]=LCM(num[i],num[i+1]);}printf("%d\n",num[i]);}}return0;}杭电1020EncodingTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):17004 AcceptedSubmission(s):7270 ProblemDescriptionGivenastringcontainingonly'A'-'Z',wecouldencodeitusingthefollowingmethod: 1.Eachsub-stringcontainingksamecharactersshouldbeencodedto"kX"where"X"istheonlycharacterinthissub-string.2.Ifthelengthofthesub-stringis1,'1'shouldbeignored. InputThefirstlinecontainsanintegerN(1<=N<=100)whichindicatesthenumberoftestcases.ThenextNlinescontainNstrings.Eachstringconsistsofonly'A'-'Z'andthelengthislessthan10000. OutputForeachtestcase,outputtheencodedstringinaline. SampleInput2ABCABBCCC SampleOutputABCA2B3C #includevoidmain(){intn;chara[10000];while(scanf("%d",&n)!=EOF){inti;getchar();while(n--){gets(a);for(i=0;a[i]!='\0';i++){inttemp=1;while(a[i]==a[i+1]){temp++;i++;}if(temp==1)printf("%c",a[i]);elseprintf("%d%c",temp,a[i]);}printf("\n");}}}杭电1166敌兵布阵TimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):20003 AcceptedSubmission(s):8757 ProblemDescriptionC国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人数都有可能发生变动,可能增加或减少若干人手,但这些都逃不过C国的监视。中央情报局要研究敌人究竟演习什么战术,所以Tidy要随时向Derek汇报某一段连续的工兵营地一共有多少人,例如Derek问:“Tidy,马上汇报第3个营地到第10个营地共有多少人!”Tidy就要马上开始计算这一段的总人数并汇报。但敌兵营地的人数经常变动,而Derek每次询问的段都不一样,所以Tidy不得不每次都一个一个营地的去数,很快就精疲力尽了,Derek对Tidy的计算速度越来越不满:"你个死肥仔,算得这么慢,我炒你鱿鱼!”Tidy想:“你自己来算算看,这可真是一项累人的工作!我恨不得你炒我鱿鱼呢!”无奈之下,Tidy只好打电话向计算机专家Windbreaker求救,Windbreaker说:“死肥仔,叫你平时做多点acm题和看多点算法书,现在尝到苦果了吧!”Tidy说:"我知错了。。。"但Windbreaker已经挂掉电话了。Tidy很苦恼,这么算他真的会崩溃的,聪明的读者,你能写个程序帮他完成这项工作吗?不过如果你的程序效率不够高的话,Tidy还是会受到Derek的责骂的. Input第一行一个整数T,表示有T组数据。每组数据第一行一个正整数N(N<=50000),表示敌人有N个工兵营地,接下来有N个正整数,第i个正整数ai代表第i个工兵营地里开始时有ai个人(1<=ai<=50)。接下来每行有一条命令,命令有4种形式:(1)Addij,i和j为正整数,表示第i个营地增加j个人(j不超过30)(2)Subij,i和j为正整数,表示第i个营地减少j个人(j不超过30);(3)Queryij,i和j为正整数,i<=j,表示询问第i到第j个营地的总人数;(4)End表示结束,这条命令在每组数据最后出现;每组数据最多有40000条命令 Output对第i组数据,首先输出“Casei:”和回车,对于每个Query询问,输出一个整数并回车,表示询问的段中的总人数,这个数保持在int以内。 SampleInput11012345678910Query13Add36Query27Sub102Add63Query310End SampleOutputCase1:63359(线段树)#include#include#defineMAX50010intnum[MAX];typedefstructnode{intlchild;intrchild;intnumber;};nodea[4*MAX];intbulit(ints,intt,intstep){intk,mid,x,y;if(s==t){a[step].
scanf("%d",&num[i]);
for(i=0;i{num[i+1]=LCM(num[i],num[i+1]);}printf("%d\n",num[i]);}}return0;}杭电1020EncodingTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):17004 AcceptedSubmission(s):7270 ProblemDescriptionGivenastringcontainingonly'A'-'Z',wecouldencodeitusingthefollowingmethod: 1.Eachsub-stringcontainingksamecharactersshouldbeencodedto"kX"where"X"istheonlycharacterinthissub-string.2.Ifthelengthofthesub-stringis1,'1'shouldbeignored. InputThefirstlinecontainsanintegerN(1<=N<=100)whichindicatesthenumberoftestcases.ThenextNlinescontainNstrings.Eachstringconsistsofonly'A'-'Z'andthelengthislessthan10000. OutputForeachtestcase,outputtheencodedstringinaline. SampleInput2ABCABBCCC SampleOutputABCA2B3C #includevoidmain(){intn;chara[10000];while(scanf("%d",&n)!=EOF){inti;getchar();while(n--){gets(a);for(i=0;a[i]!='\0';i++){inttemp=1;while(a[i]==a[i+1]){temp++;i++;}if(temp==1)printf("%c",a[i]);elseprintf("%d%c",temp,a[i]);}printf("\n");}}}杭电1166敌兵布阵TimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):20003 AcceptedSubmission(s):8757 ProblemDescriptionC国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人数都有可能发生变动,可能增加或减少若干人手,但这些都逃不过C国的监视。中央情报局要研究敌人究竟演习什么战术,所以Tidy要随时向Derek汇报某一段连续的工兵营地一共有多少人,例如Derek问:“Tidy,马上汇报第3个营地到第10个营地共有多少人!”Tidy就要马上开始计算这一段的总人数并汇报。但敌兵营地的人数经常变动,而Derek每次询问的段都不一样,所以Tidy不得不每次都一个一个营地的去数,很快就精疲力尽了,Derek对Tidy的计算速度越来越不满:"你个死肥仔,算得这么慢,我炒你鱿鱼!”Tidy想:“你自己来算算看,这可真是一项累人的工作!我恨不得你炒我鱿鱼呢!”无奈之下,Tidy只好打电话向计算机专家Windbreaker求救,Windbreaker说:“死肥仔,叫你平时做多点acm题和看多点算法书,现在尝到苦果了吧!”Tidy说:"我知错了。。。"但Windbreaker已经挂掉电话了。Tidy很苦恼,这么算他真的会崩溃的,聪明的读者,你能写个程序帮他完成这项工作吗?不过如果你的程序效率不够高的话,Tidy还是会受到Derek的责骂的. Input第一行一个整数T,表示有T组数据。每组数据第一行一个正整数N(N<=50000),表示敌人有N个工兵营地,接下来有N个正整数,第i个正整数ai代表第i个工兵营地里开始时有ai个人(1<=ai<=50)。接下来每行有一条命令,命令有4种形式:(1)Addij,i和j为正整数,表示第i个营地增加j个人(j不超过30)(2)Subij,i和j为正整数,表示第i个营地减少j个人(j不超过30);(3)Queryij,i和j为正整数,i<=j,表示询问第i到第j个营地的总人数;(4)End表示结束,这条命令在每组数据最后出现;每组数据最多有40000条命令 Output对第i组数据,首先输出“Casei:”和回车,对于每个Query询问,输出一个整数并回车,表示询问的段中的总人数,这个数保持在int以内。 SampleInput11012345678910Query13Add36Query27Sub102Add63Query310End SampleOutputCase1:63359(线段树)#include#include#defineMAX50010intnum[MAX];typedefstructnode{intlchild;intrchild;intnumber;};nodea[4*MAX];intbulit(ints,intt,intstep){intk,mid,x,y;if(s==t){a[step].
num[i+1]=LCM(num[i],num[i+1]);
printf("%d\n",num[i]);
杭电1020
Encoding
17004 AcceptedSubmission(s):
7270
Givenastringcontainingonly'A'-'Z',wecouldencodeitusingthefollowingmethod:
1.Eachsub-stringcontainingksamecharactersshouldbeencodedto"kX"where"X"istheonlycharacterinthissub-string.
2.Ifthelengthofthesub-stringis1,'1'shouldbeignored.
ThefirstlinecontainsanintegerN(1<=N<=100)whichindicatesthenumberoftestcases.ThenextNlinescontainNstrings.Eachstringconsistsofonly'A'-'Z'andthelengthislessthan10000.
Foreachtestcase,outputtheencodedstringinaline.
ABC
ABBCCC
A2B3C
intn;
chara[10000];
while(scanf("%d",&n)!
inti;
getchar();
while(n--)
gets(a);
for(i=0;a[i]!
='\0';i++)
inttemp=1;
while(a[i]==a[i+1])
temp++;
i++;
if(temp==1)
printf("%c",a[i]);
else
printf("%d%c",temp,a[i]);
杭电1166
敌兵布阵
20003 AcceptedSubmission(s):
8757
C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。
A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。
由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人数都有可能发生变动,可能增加或减少若干人手,但这些都逃不过C国的监视。
中央情报局要研究敌人究竟演习什么战术,所以Tidy要随时向Derek汇报某一段连续的工兵营地一共有多少人,例如Derek问:
“Tidy,马上汇报第3个营地到第10个营地共有多少人!
”Tidy就要马上开始计算这一段的总人数并汇报。
但敌兵营地的人数经常变动,而Derek每次询问的段都不一样,所以Tidy不得不每次都一个一个营地的去数,很快就精疲力尽了,Derek对Tidy的计算速度越来越不满:
"你个死肥仔,算得这么慢,我炒你鱿鱼!
”Tidy想:
“你自己来算算看,这可真是一项累人的工作!
我恨不得你炒我鱿鱼呢!
”无奈之下,Tidy只好打电话向计算机专家Windbreaker求救,Windbreaker说:
“死肥仔,叫你平时做多点acm题和看多点算法书,现在尝到苦果了吧!
”Tidy说:
"我知错了。
。
"但Windbreaker已经挂掉电话了。
Tidy很苦恼,这么算他真的会崩溃的,聪明的读者,你能写个程序帮他完成这项工作吗?
不过如果你的程序效率不够高的话,Tidy还是会受到Derek的责骂的.
第一行一个整数T,表示有T组数据。
每组数据第一行一个正整数N(N<=50000),表示敌人有N个工兵营地,接下来有N个正整数,第i个正整数ai代表第i个工兵营地里开始时有ai个人(1<=ai<=50)。
接下来每行有一条命令,命令有4种形式:
(1)Addij,i和j为正整数,表示第i个营地增加j个人(j不超过30)
(2)Subij,i和j为正整数,表示第i个营地减少j个人(j不超过30);
(3)Queryij,i和j为正整数,i<=j,表示询问第i到第j个营地的总人数;
(4)End表示结束,这条命令在每组数据最后出现;
每组数据最多有40000条命令
对第i组数据,首先输出“Casei:
”和回车,
对于每个Query询问,输出一个整数并回车,表示询问的段中的总人数,这个数保持在int以内。
10
12345678910
Query13
Add36
Query27
Sub102
Add63
Query310
End
6
33
59
(线段树)
#defineMAX50010
intnum[MAX];
typedefstructnode{
intlchild;
intrchild;
intnumber;
};
nodea[4*MAX];
intbulit(ints,intt,intstep)
intk,mid,x,y;
if(s==t)
a[step].
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1