杭州电子科技大学acm习题集锦_第1页
杭州电子科技大学acm习题集锦_第2页
杭州电子科技大学acm习题集锦_第3页
杭州电子科技大学acm习题集锦_第4页
杭州电子科技大学acm习题集锦_第5页
已阅读5页,还剩17页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、第第 #页共21页intnum;intn,m;scanf(%d,&num);memset(arr,0,MAX*sizeof(int);while(num-)scanf(%d%d,&n,&m);printf(%ldn,solve(n,m);return0;贪心策略FatMouseTradeProblemDescriptionFatMousepreparedMpoundsofcatfood,readytotradewiththecatsguardingthewarehousecontaininghisfavoritefood,JavaBean.ThewarehousehasNrooms.Thei-

2、throomcontainsJipoundsofJavaBeansandrequiresFipoundsofcatfood.FatMousedoesnothavetotradeforalltheJavaBeansintheroom,instead,hemaygetJi*a%poundsofJavaBeansifhepaysFi*a%poundsofcatfood.Hereaisarealnumber.Nowheisassigningthishomeworktoyou:tellhimthemaximumamountofJavaBeanshecanobtain.InputTheinputconsi

3、stsofmultipletestcases.Eachtestcasebeginswithalinecontainingtwonon-negativeintegersMandN.ThenNlinesfollow,eachcontainstwonon-negativeintegersJiandFirespectively.Thelasttestcaseisfollowedbytwo-1s.Allintegersarenotgreaterthan1000.OutputForeachtestcase,printinasinglelinearealnumberaccurateupto3decimalp

4、laces,whichisthemaximumamountofJavaBeansthatFatMousecanobtain.2415151024151510-1-1SampleOutput13.33331.50037243522032518#include#include#defineMAX1000intmain()inti,j,m,n,temp;intJMAX,FMAX;doublePMAX;doublesum,temp1;scanf(%d%d,&m,&n);while(m!=-1&n!=-1)sum=0;memset(J,0,MAX*sizeof(int);memset(F,0,MAX*s

5、izeof(int);memset(P,0,MAX*sizeof(double);for(i=0;in;i+)scanf(%d%d,&Ji,&Fi);Pi=Ji*1.0/(double)Fi);for(i=0;in;i+)for(j=i+1;jn;j+)if(PiPj)temp1=Pi;Pi=Pj;Pj=temp1;temp=Ji;Ji=Jj;Jj=temp;temp=Fi;Fi=Fj;Fj=temp;for(i=0;in;i+)if(mFi)sum+=m/(double)Fi)*Ji;break;elsesum+=Ji;m-=Fi;printf(%.3lfn,sum);scanf(%d%d,

6、&m,&n);return0;今年暑假不ACProblemDescription确实如此,世界杯来了,球迷的节日也来了,估计很多ACMer也会抛开电脑,奔向电视了。作为球迷,一定想看尽量多的完整的比赛,当然,作为新时代的好青年,你一定还会看一些其它的节目,比如新闻联播(永远不要忘记关心国家大事)、非常6+7、超级女生,以及王小丫的开心辞典等等,假设你已经知道了所有你喜欢看的电视节目的转播时间表,你会合理安排吗?(目标是能看尽量多的完整节目)Input输入数据包含多个测试实例,每个测试实例的第一行只有一个整数n(nv=100),表示你喜欢看的节目的总数,然后是n行数据,每行包括两个数据Ti_s,

7、Ti_e(1v=iv=n),分别表示第i个节目的开始和结束时间,为了简化问题,每个时间都用一个正整数表示。n=0表示输入结束,不做处理。Output对于每个测试实例,输出能完整看到的电视节目的个数,每个测试实例的输出占一行。SampleInput1213340738151915201015#include#defineMAX200intarrMAX2;intnum;voidres()inti,j;intstart;intcount=0,max=-1;for(i=num-1;i=num/2;i-)if(countmax)max=count;count=1;start=arri0;for(j=i-

8、1;j=0;j-)if(arrj1=start)count+;printf(%dn,max);voidprc()inti,j;for(i=0;inum;i+)scanf(%d%d,&arri0,&arri1);for(i=0;inum;i+)/排序for(j=i+1;jarrj0)818612510818612510414290SampleOutput5start=arrj0;arri1+=arrj1;arrj1=arri1-arrj1;arri1=arri1-arrj1;if(arri0=arrj0)&(arri1arrj1)arri1+=arrj1;arrj1=arri1-arrj1;ar

9、ri1=arri1-arrj1;res();intmain()scanf(%d,&num);while(num)prc();scanf(%d,&num);return0;几何问题RectanglesProblemDescriptionGiventworectanglesandthecoordinatesoftwopointsonthediagonalsofeachrectangle,youhavetocalculatetheareaoftheintersectedpartoftworectangles.itssidesareparalleltoOXandOY.InputInputThefirs

10、tlineofinputis8positivenumberswhichindicatethecoordinatesoffourpointsthatmustbeoneachdiagonal.The8numbersarex1,y1,x2,y2,x3,y3,x4,y4.Thatmeansthetwopointsonthefirstrectangleare(x1,y1),(x2,y2);theothertwopointsonthesecondrectangleare(x3,y3),(x4,y4).OutputOutputForeachcaseoutputtheareaoftheirintersecte

11、dpartinasingleline.,accurateupto2decimalplaces.SampleInput1.001.003.003.002.002.004.004.005.005.0013.0013.004.004.0012.5012.50SampleOutput1.0056.25#includevoidres(doublex1,doubley1,doublex2,doubley2,doublex3,doubley3,doublex4,doubley4)doubletmpx1,tmpy1,tmpx2,tmpy2;doubletmpx,tmpy;tmpx=x1+x2;x1=(x1x2

12、)?x2:x1;x2=tmpx-x1;tmpy=y1+y2;y1=(y1y2)?y2:y1;y2=tmpy-y1;tmpx=x3+x4;x3=(x3x4)?x4:x3;x4=tmpx-x3;tmpy=y3+y4;y3=(y3y4)?y4:y3;y4=tmpy-y3;tmpx1=(x1x3)?x1:x3;tmpx2=(x2x4)?x4:x2;tmpy1=(y1y3)?y1:y3;tmpy2=(y2y4)?y4:y2;if(tmpx1tmpx2&tmpy1tmpy2)printf(%.2lfn,(tmpx1-tmpx2)*(tmpy1-tmpy2);elseprintf(0.00n);intmai

13、n()doublex1,y1,x2,y2;doublex3,y3,x4,y4;while(scanf(%lf%lf%lf%lf%lf%lf%lf%lf,&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4)!=EOF)res(x1,y1,x2,y2,x3,y3,x4,y4);return0;无限的路ProblemDescription甜甜从小就喜欢画图画,最近他买了一支智能画笔,由于刚刚接触,所以甜甜只会用它来画直线,于是他就在平面直角坐标系中画出如下的图形:5)(04)甜甜的好朋友蜜蜜个点,请你算一算第一个数是正整数每组数据由四个非Outpu甜甜的好朋友蜜蜜个点,请你算一算第一个数

14、是正整数每组数据由四个非Outpu0j)对于每组数据、输位。连接两点&是有点规则的,于是他问甜甜:在你画的图中,我给你两层长度(即沿折线走的路线长度)吧。数据的组数。数组成Xj,y1,X2,y2;有的数都不会大于100。两点(X1,y1),(X2y2)之间的折线距离。注意输出结果精确到小数点后3Sample.Inputo.o:D;3,0:.4.09999氐9:5555500010010SampleOutput1.00023312.41410.6460.00054985.047#include#include#includeusingnamespacestd;intmain(void)intn,x3,y3;doubles;scanf(%d,&n);while(n-&scanf(%d%d%d%d,x,y,x+1,y+1)if(x2=x0+y0)(y2=x

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论