杭电部分题目.docx

上传人:b****6 文档编号:6548352 上传时间:2023-01-07 格式:DOCX 页数:42 大小:60.36KB
下载 相关 举报
杭电部分题目.docx_第1页
第1页 / 共42页
杭电部分题目.docx_第2页
第2页 / 共42页
杭电部分题目.docx_第3页
第3页 / 共42页
杭电部分题目.docx_第4页
第4页 / 共42页
杭电部分题目.docx_第5页
第5页 / 共42页
点击查看更多>>
下载资源
资源描述

杭电部分题目.docx

《杭电部分题目.docx》由会员分享,可在线阅读,更多相关《杭电部分题目.docx(42页珍藏版)》请在冰豆网上搜索。

杭电部分题目.docx

杭电部分题目

杭电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

#include

#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;j

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

key[i]=str[i]-'A'+1;

}

sort(key,len);

for(i=0;i

for(j=0;j

if(i==j)

continue;

for(k=0;k

if(k==i||k==j)

continue;

for(l=0;l

if(l==k||l==i||l==j)

continue;

for(m=0;m

if(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:

AMathematicalCuriosity

TimeLimit:

2000/1000MS(Java/Others)    MemoryLimit:

65536/32768K(Java/Others)

TotalSubmission(s):

16821    AcceptedSubmission(s):

5238

 

ProblemDescription

Giventwointegersnandm,countthenumberofpairsofintegers(a,b)suchthat0

Thisproblemcontainsmultipletestcases!

ThefirstlineofamultipleinputisanintegerN,thenablanklinefollowedbyNinputblocks.Eachinputblockisintheformatindicatedintheproblemdescription.Thereisablanklinebetweeninputblocks.

TheoutputformatconsistsofNoutputblocks.Thereisablanklinebetweenoutputblocks.

 

Input

Youwillbegivenanumberofcasesintheinput.Eachcaseisspecifiedbyalinecontainingtheintegersnandm.Theendofinputisindicatedbyacaseinwhichn=m=0.Youmayassumethat0

 

Output

Foreachcase,printthecasenumberaswellasthenumberofpairs(a,b)satisfyingthegivenproperty.Printtheoutputforeachcaseononelineintheformatasshownbelow.

 

SampleInput

1

101

203

304

00

 

SampleOutput

Case1:

2

Case2:

4

Case3:

5

#include

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");

}

}

}

 

}

 

杭电1019

LeastCommonMultiple

TimeLimit:

2000/1000MS(Java/Others)    MemoryLimit:

65536/32768K(Java/Others)

TotalSubmission(s):

17599    AcceptedSubmission(s):

6554

 

ProblemDescription

Theleastcommonmultiple(LCM)ofasetofpositiveintegersisthesmallestpositiveintegerwhichisdivisiblebyallthenumbersintheset.Forexample,theLCMof5,7and15is105.

 

Input

Inputwillconsistofmultipleprobleminstances.Thefirstlineoftheinputwillcontainasingleintegerindicatingthenumberofprobleminstances.Eachinstancewillconsistofasinglelineoftheformmn1n2n3...nmwheremisthenumberofintegersinthesetandn1...nmaretheintegers.Allintegerswillbepositiveandliewithintherangeofa32-bitinteger.

 

Output

Foreachprobleminstance,outputasinglelinecontainingthecorrespondingLCM.Allresultswilllieintherangeofa32-bitinteger.

 

SampleInput

2

35715

641029693612877921

 

SampleOutput

105

10296

 

Source

EastCentralNorthAmerica2003,Practice

 

#include

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;

}

杭电1020

Encoding

TimeLimit:

2000/1000MS(Java/Others)    MemoryLimit:

65536/32768K(Java/Others)

TotalSubmission(s):

17004    AcceptedSubmission(s):

7270

 

ProblemDescription

Givenastringcontainingonly'A'-'Z',wecouldencodeitusingthefollowingmethod:

 

1.Eachsub-stringcontainingksamecharactersshouldbeencodedto"kX"where"X"istheonlycharacterinthissub-string.

2.Ifthelengthofthesub-stringis1,'1'shouldbeignored.

 

Input

ThefirstlinecontainsanintegerN(1<=N<=100)whichindicatesthenumberoftestcases.ThenextNlinescontainNstrings.Eachstringconsistsofonly'A'-'Z'andthelengthislessthan10000.

 

Output

Foreachtestcase,outputtheencodedstringinaline.

 

SampleInput

2

ABC

ABBCCC

 

SampleOutput

ABC

A2B3C

 

#include

voidmain()

{

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]);

else

printf("%d%c",temp,a[i]);

}

printf("\n");

}

}

}

杭电1166

敌兵布阵

TimeLimit:

2000/1000MS(Java/Others)    MemoryLimit:

65536/32768K(Java/Others)

TotalSubmission(s):

20003    AcceptedSubmission(s):

8757

 

ProblemDescription

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的责骂的.

 

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以内。

 

SampleInput

1

10

12345678910

Query13

Add36

Query27

Sub102

Add63

Query310

End

 

SampleOutput

Case1:

6

33

59

(线段树)

#include

#include

#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