ACM第二学期题目报告.docx

上传人:b****5 文档编号:11663537 上传时间:2023-03-29 格式:DOCX 页数:28 大小:120.94KB
下载 相关 举报
ACM第二学期题目报告.docx_第1页
第1页 / 共28页
ACM第二学期题目报告.docx_第2页
第2页 / 共28页
ACM第二学期题目报告.docx_第3页
第3页 / 共28页
ACM第二学期题目报告.docx_第4页
第4页 / 共28页
ACM第二学期题目报告.docx_第5页
第5页 / 共28页
点击查看更多>>
下载资源
资源描述

ACM第二学期题目报告.docx

《ACM第二学期题目报告.docx》由会员分享,可在线阅读,更多相关《ACM第二学期题目报告.docx(28页珍藏版)》请在冰豆网上搜索。

ACM第二学期题目报告.docx

ACM第二学期题目报告

开放性实验ACM部分实验报告

ZOJProblemSet-1057

1057Undercut

TimeLimit:

1Second    MemoryLimit:

32768KB

Undercutisacardgamewheretwoplayerseachhavefivecardsnumberedonethroughfive.Ateachround,eachplayerselectsacard,thensimultaneouslyrevealsit.Ifthecardsareofequalvalue,thereisnoscore.Otherwise,therearetwocases:

thetwocardsareexactlyonepointapart(thisiscalledanundercut),orthecardsaremorethanonepointapart.Inthelattercase,thepersonrevealingthelargerofthecardsgetsthenumberofpointsonthelargercard.Inthecaseofanundercuttheplayerwiththelowercardgetsthesumofthetwocards.Theexception[例外情况]tothisiswhenthecardsare1and2,inwhichcasetheplayerwiththelowercardgets6points(insteadofonly3points).Aftereachround,thecardsarereturnedtothehandsandtheyplayanotherround.

Forexample,ifthereare5roundsandplayerAplays(inthisorder)5,3,1,3,5andplayerBplays3,3,3,3,4,thenthescoringforeachroundwouldbe:

Agets5points,nopoints,Bgets3points,nopoints,Bgets9points.ThetotalswouldbeA:

5,B:

12.

Inthisproblemyouwillbegivencardplaysforbothplayersandmustdeterminethefinalscores.

Input

Therewillbemultipleinputinstances.Eachinstancewillbeonegame.Thefirstlineofinputforagamewillbeanintegern<=20.(Avalueofn=0terminatesinput.)Thenexttwolineswilleachcontainnintegersbetween1and5inclusiveindicatingthecardsplayedoneachofnrounds.ThefirstlineareplayerA'scardplaysandthesecondlineareplayerB'scardplays.

Output

Eachinputinstanceshouldgenerateonelineofoutputoftheform:

Ahasapoints.Bhasbpoints.

wherethevalueofaandbareforyoutodetermine.Ablanklineshouldseparateoutputlines.

SampleInput

5

53135

33334

4

2311

1555

0

SampleOutput

Ahas5points.Bhas12points.

Ahas0points.Bhas21points.

题意:

A、B玩牌,若牌的点数相同则双方均不得分,若相差一分,则牌点数较小的得分(两张点数之和),若大于一分,则点数较大者得到两张牌中点数较大的分值,一个例外情况,当牌点数为1、2时,较低者得6分,其中牌点数在1~5之间

思路:

由以上题目可得ifelse的思路,重点在于空行的位置的输出,应该在第二次n的值输入后打出空行

代码:

#include

intmain()

{

inta[21],b[21],i,sa,sb,n,j=1;

scanf("%d",&n);

while

(1)

{

sa=0;

sb=0;

for(i=0;i

scanf("%d",&a[i]);

for(i=0;i

scanf("%d",&b[i]);

for(i=0;i

{

if(a[i]==1&&b[i]==2)

sa+=6;

elseif(a[i]==2&&b[i]==1)

sb+=6;

elseif(a[i]-b[i]==1||a[i]-b[i]==-1)

{

if(a[i]

sa+=a[i]+b[i];

else

sb+=a[i]+b[i];

}

elseif(a[i]-b[i]>1||a[i]-b[i]<-1)

{

if(a[i]>b[i])

sa=sa+a[i];

else

sb+=b[i];

}

}

printf("Ahas%dpoints.Bhas%dpoints.\n",sa,sb);

scanf("%d",&n);

if(n)

printf("\n");

else

break;

}

return0;

}

代码效果:

ZOJProblemSet-1078

1078PalindromeNumbers

TimeLimit:

1Second    MemoryLimit:

32768KB

StatementoftheProblem

Wesaythatanumberisapalindromifitisthesanewhenreadfromlefttorightorfromrighttoleft.Forexample,thenumber75457isapalindrom.

Ofcourse,thepropertydependsonthebasisinwhichisnumberisrepresented.Thenumber17isnotapalindrominbase10,butitsrepresentationinbase2(10001)isapalindrom.

Theobjectiveofthisproblemistoverifyifasetofgivennumbersarepalindromsinanybasisfrom2to16.

InputFormat

Severalintegernumberscomprisetheinput.Eachnumber0

OutputFormat

YourprogrammustprintthemessageNumberiispalindrominbasiswhereIisthegivennumber,followedbythebasiswheretherepresentationofthenumberisapalindrom.Ifthenumberisnotapalindrominanybasisbetween2and16,yourprogrammustprintthemessageNumberiisnotpalindrom.

SampleInput

17

19

0

SampleOutput

Number17ispalindrominbasis2416

Number19isnotapalindrom

题意:

判断所给数字是否为回文数,判断依据:

若该数字的n(2-16)进制的表示对称,则输出相关的进制

思路:

写出一个十进制转化为n进制的函数,然后判断是否对称,若是则存进一个数组,循环结束后打出

代码:

代码效果:

ZOJProblemSet-1195

1195BlowingFuses

TimeLimit:

1Second    MemoryLimit:

32768KB

Maybeyouarefamiliarwiththefollowingsituation.Youhavepluggedinalotofelectricaldevices,suchastoasters,refrigerators,microwaveovens,computers,stereos,etc,andhavethemallrunning.ButatthemomentwhenyouturnontheTV,thefuseblows,sincethepowerdrawnfrom[从中得到、从……提取]allthemachinesisgreaterthanthecapacity[容量、能力]ofthefuse.Ofcoursethisisagreatsafetyfeature,avoidingthathousesburndowntoooftenduetofiresignitedbyoverheatingwires.Butitisalsoannoyingtowalkdowntothebasement(orsomeotherinconvenientplace)toreplacetofuseorswitchitbackon.

Whatonewouldliketohaveisaprogramthatchecksbeforeturningonanelectricaldevicewhetherthecombinedpowerdrawnbyallrunningdevicesexceedsthefusescapacity(anditblows),orwhetheritissafetoturniton.

Input

Theinputconsistsofseveraltestcases.Eachtestcasedescribesasetofelectricaldevicesandgivesasequenceofturnon/offoperationsforthesedevices.

Thefirstlineofeachtestcasecontainsthreeintegersn,mandc,wherenisthenumberofdevices(n<=20),mthenumberofoperationsperformedon[上演]thesedevicesandcisthecapacityofthefuse(inAmperes).Thefollowingnlinescontainonepositiveintegercieach,theconsumption(inAmperes)ofthei-thdevice.

Thisisfollowedbymlinesalsocontainingoneintegereach,between1andninclusive.Theydescribeasequenceofturnon/turnoffoperationsperformedonthedevices.Foreverynumber,thestateofthatparticulardeviceistoggled,i.e.ifitiscurrentlyrunning,itisturnedoff,andifitiscurrentlyturnedoff,itwillbeswitchedon.Atthebeginningalldevicesareturnedoff.

Theinputwillbeterminatedbyatestcasestartingwithn=m=c=0.Thistestcaseshouldnotbeprocessed.

Output

Foreachtestcase,firstoutputthenumberofthetestcase.Thenoutputwhetherthefusewasblownduringtheoperationsequence.Thefusewillbeblownifthesumofthepowerconsumptionsciofturnedondevicesatsomepointexceedsthecapacityofthefusec.

Ifthefuseisnotblown,outputthemaximalpowerconsumptionbyturnedondevicesthatoccurredduringthesequence.

Outputablanklineaftereachtestcase.

SampleInput

2210

5

7

1

2

3610

2

5

7

2

1

2

3

1

3

000

SampleOutput

Sequence1

Fusewasblown.

Sequence2

Fusewasnotblown.

Maximalpowerconsumptionwas9amperes.

题意:

计算正在使用的电器的电流量是否超过了最大电容量,若是输出“Fusewasblown.”,若不是,则输出“Fusewasnotblown.Maximalpowerconsumptionwas9amperes.”,第一行为电器数、每台电器所需电流量、对相应电器的操作(开关)

思路:

输入操作数的值,然后进行相应的加减,最后判断是否超出最大值,相应输出

代码:

#include

#include

intmain()

{

intm,n,c,i,j=1,dev[21],oper[21],nc,maxc,t;

while(scanf("%d%d%d",&n,&m,&c)!

=EOF&&m!

=0&&n!

=0&&c!

=0)

{

intflag=0;

memset(oper,0,sizeof(oper));

nc=maxc=0;

for(i=1;i<=n;i++)

scanf("%d",&dev[i]);

for(i=1;i<=m;i++)

{

scanf("%d",&t);

if(flag)

continue;

if(oper[t]==0)

{

oper[t]=1;

nc+=dev[t];

if(nc>c)

flag=1;

elseif(nc>maxc)

maxc=nc;

}

else

{

oper[t]=0;

nc-=dev[t];

}

}

printf("Sequence%d\n",j++);

if(flag)

printf("Fusewasblown.\n\n");

else

printf("Fusewasnotblown.\nMaximalpowerconsumptionwas%damperes.\n\n",maxc);

}

return0;

}

代码效果:

ZOJProblemSet-1272

1272NumericallySpeaking

TimeLimit:

1Second    MemoryLimit:

32768KB

Adeveloperofcrosswordpuzzles[填字游戏](andothersimilarwordgames)hasdecidedtodevelopamappingbetweeneverypossiblewordwithfromonetotwentycharactersanduniqueintegers.Themappingisverysimple,withtheorderingbeingdonefirstbythelengthoftheword,andthenalphabetically[照字母顺序排列地].Partofthelistisshownbelow.

a         1

  b         2

   ...

   z         26

   aa        27

   ab        28

   ...

   snowfall  157,118,051,752

   ...

Yourjobinthisproblemistodevelopaprogramwhichcantranslate,bidirectionally[变形的],betweentheuniquewordnumbersandthecorrespondingwords.

Input

Inputtotheprogramisalistofwordsandnumbers,oneperlinestartingincolumnone,followedbyalinecontainingasingleasteriskincolumn[列]one.Anumberwillconsistonlyofdecimaldigits[小数位数](0through9)followedimmediatelybytheendofline(thatis,therewillbenocommasininputnumbers).Awordwillconsistofbetweenoneandtwentylowercasealphabeticcharacters[字母符号](athroughz).

Output

Theoutputistocontainasinglelineforeachwordornumberintheinputdata.Thislineistocontainthewordstartingincolumnone,followedbyanappropriatenumberofblanks,andthecorrespondingwordnumberstartingincolumn23.Wordnumbersthathavemorethanthreedigitsmustbeseparatedbycommas[逗号]atthousands,millions,andsoforth.

SampleInput

29697684282993

transcendental

28011622636823854456520

computationally

zzzzzzzzzzzzzzzzzzzz

*

SampleOutput

elementary           29,697,684,282,993

transcendental      51,346,529,199,396,181,750

prestidigitation     28,011,622,636,823,854,456,520

computationally      232,049,592,627,851,629,097

zzzzzzzzzzzzzzzzzzzz 20,725,274,851,017,785,518,433,805,270

题意:

对长度在23位之内的字母或字符进行10进制与26进制之间的转换

思路:

不会

代码:

代码效果:

ZOJProblemSet-1489

14892^xmodn=1

TimeLimit:

1Second    MemoryLimit:

32768KB

Giveanumbern,findtheminimumxthatsatisfies2^xmodn=1.

Input

Onepositiveintegeroneachline,thevalueofn.

Output

Iftheminimumxexists,printalinewith2^xmodn=1.

Print2^?

modn=1

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工程科技 > 能源化工

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1