ACM第二学期题目报告.docx
- 文档编号:8020059
- 上传时间:2023-05-12
- 格式:DOCX
- 页数:28
- 大小:120.94KB
ACM第二学期题目报告.docx
《ACM第二学期题目报告.docx》由会员分享,可在线阅读,更多相关《ACM第二学期题目报告.docx(28页珍藏版)》请在冰点文库上搜索。
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
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- ACM 第二 学期 题目 报告