zoj23922312实验报告英文+翻译.docx

上传人:b****1 文档编号:18007200 上传时间:2023-04-24 格式:DOCX 页数:15 大小:28.97KB
下载 相关 举报
zoj23922312实验报告英文+翻译.docx_第1页
第1页 / 共15页
zoj23922312实验报告英文+翻译.docx_第2页
第2页 / 共15页
zoj23922312实验报告英文+翻译.docx_第3页
第3页 / 共15页
zoj23922312实验报告英文+翻译.docx_第4页
第4页 / 共15页
zoj23922312实验报告英文+翻译.docx_第5页
第5页 / 共15页
点击查看更多>>
下载资源
资源描述

zoj23922312实验报告英文+翻译.docx

《zoj23922312实验报告英文+翻译.docx》由会员分享,可在线阅读,更多相关《zoj23922312实验报告英文+翻译.docx(15页珍藏版)》请在冰豆网上搜索。

zoj23922312实验报告英文+翻译.docx

zoj23922312实验报告英文+翻译

算法分析大型实验报告

编号

标题

算法

题目一

2392

TheCountingProblem

模拟

题目二

2312

JapanPlotterDriver

模拟

班级:

软件1002

姓名:

徐潇

学号:

201020630222

指导老师:

赵端阳

 

2012年8月

TheCountingProblem

TimeLimit:

 2Seconds     MemoryLimit:

 65536KB

Giventwointegersaandb,wewritethenumbersbetweenaandb,inclusive,inalist.Yourtaskistocalculatethenumberofoccurrencesofeachdigit.Forexample,ifa=1024andb=1032,thelistwillbe

102410251026102710281029103010311032

thereareten0sinthelist,ten1s,seven2s,three3s,andetc.

Input

Theinputconsistsofupto500lines.Eachlinecontainstwonumbersaandbwhere0

Output

Foreachpairofinput,outputalinecontainingtennumbersseparatedbysinglespaces.Thefirstnumberisthenumberofoccurrencesofthedigit0,thesecondisthenumberofoccurrencesofthedigit1,etc.

SampleInput

110

44497

346542

11991748

14961403

1004503

1714190

1317854

1976494

10011960

00

SampleOutput

1211111111

851851851851909696969593

404040931368240404040

115666215215214205205154105106

1611319201142020191916

107105100101101197200200200200

4131133503503503502502417402412

19651218610487939797142196

3981375398398405499499495488471

2941256296296296296287286286247

 

【全文翻译】

计数问题

给定2个整数a和b,在a和b之间写下号码,包含在一个列表里面。

你的任务是计算每个数字出现的次数。

例如,如果a=1024,b=1032,这列数为:

102410251026102710281029103010311032有10个零,10个1,7个2,3个3等等。

输入

输入500行以下。

每行包含一个数,其中0

输入一行是“00”时终止,这是不被视为部分输入。

输出

对每个输入,输出一行由单个空格分隔的十个数字。

第一个是0出现的次数,其次是1,诸如此类。

【算法分析】

题目:

TheCountingProblem

提交语言:

C++

运行时间:

0ms

运行内存:

188KB

#include

#include

#include

#include

#include

#include

#include

usingnamespacestd;

#defineSZ(v)((int)(v).size())

intS,T;

intres[10],dig[20],len;

voidsolve(intNum){

   Num++;

   len=0;

   inttemp=1;

   while

(1){

       dig[++len]=Num%10;

       Num/=10;

       if(!

Num)   break;

       temp*=10;

   }

   for(inti=1;i<10;i++)  res[i]+=(len-1)*temp/10;

   res[0]+=(len-1)*temp/10-(temp-1)/9;

    

   for(inti=1;i

       res[i]+=temp;

       for(intj=0;j<10;j++){

           res[j]+=(len-1)*temp/10;

       }

   }

   temp/=10;

   for(inti=len-1;i>=1;i--){

       for(intj=0;j

           for(intk=len;k>i;k--){

               res[dig[k]]+=temp;

           }

           res[j]+=temp;

           for(intk=0;k<10;k++){

               res[k]+=(i-1)*temp/10;

           }

       }

       temp/=10;

   }

}

intmain(){

   while(scanf("%d%d",&S,&T)!

=EOF){

       if(S+T==0)break;

       memset(res,0,sizeof(res));

       if(S>T)swap(S,T);

       solve(S-1);

       for(inti=0;i<10;i++)  res[i]=-res[i];

       solve(T);

       for(inti=0;i<10;i++)printf(i==9?

"%d\n":

"%d",res[i]);

   }

   return0;

}

ZOJProblemSet–2312

JapanPlotterDriver

TimeLimit:

2Seconds    MemoryLimit:

65536KB

TheJapancompanyyouareworkingforproduceplotterdevicesthatcandrawnicepictures.Tosupportcustomerswhodonotpossesthespecialhardware,youwereaskedtowriteanemulationdriverthatsimulatestheworkoftheplotterandprintsthepictureonacomputerscreen.

Theplotterisdrivenwithasimplelanguageconsistingofseveraldrawingcommands:

POINTxy--makesalittlecircleatthegivencoordinates.

TEXTxytxt--displaysalineoftextatthegivencoordinates.

LINEx1y1x2y2--drawsalinebetweenthespecifiedpoints.

CLEARx1y1x2y2--erasesthegivenrectangle.

PRINT--printsanoutputpageandterminatesthecurrentjob.

TheemulationdriverusesfewASCIIcharacterstorepresentthepicture,onecharacterbeingabasicunitofthecoordinatesystem.Thetop-leftcharacterhascoordinates(1,1).TheX-axisaimstotheright,theY-axisgoesdown.

Theparticularcommandsareemulatedasfollows:

POINT:

Thedriverputsalowercaseletter"o"atthegivencoordinates.

TEXT:

Showsasinglelineoftext,thefirstcharacterispositionedatthegivencoordinatesandthetextalwaysgoesright.

LINE:

Simulatesastraightlinebetweentwopoints.Thelineisformedbyoneofthefollowingcharacters:

dash("-"),pipe("|"),slash("/"),orbackslash("\"),accordingtoitsdirection.

CLEAR:

Thedriverfillstheappropriaterectangularareawithspaces,includingtheboundingrowsandcolumns.

PRINT:

Thiscommandcausesthedrivertoprintthepicturesurroundedwithaniceframemadeofplus("+"),minus("-"),andpipe("|")characters.

Ifmoreobjectsshouldbedrawnacrossasinglecharacter,thefollowingrulesapply:

Ifthesamecharacterisdrawnseveraltimes,itisusedwithoutachange.

Ifonlypipeandminuscharactersareinvolved,theyresultintheplussign("+").

Ifonlyslashesandbackslashesareinvolved,theresultisthelowercaseletter"x".

Otherwise,theasterisk("*")isdisplayed.

Beforeascriptisgiventothedriver,itischeckedbyaspecialpreprocessor,whichrejectsallinvalidcommands.Therefore,youmayassumethatallcoordinatesarewithintherangeofthepage.Also,withtheLINEcommand,thetwopointsarealwaysdifferentandthelineisstrictlyeithervertical,horizontal,orattheangleof45ototheaxes.ThereisnoassumptionontherelativepositionofthepointsusedwiththeLINEandCLEARcommands.ThetextintheTEXTcommandisalwayscomposedonlyofuppercaseletteranddigits.

Input

Theinputconsistsofseveralscripts.EachscriptbeginswithalinecontainingtwointegersXandY,separatedwithspace,1<=X,Y<=75.Thesenumbersspecifythedimensionsofthepage.Everyotherlinecontainsexactlyoneoftheabovecommands.Thecommandsarealwaysuppercase,commandargumentsareseparatedwithonespace.

ThePRINTcommandisalwaysthelastcommandofthescript.AfterthePRINTcommand,anewscriptbegins.Theinputisterminatedwithtwozeros,whicharenotconsideredtobeascript.

Output

Foreachscript,outputtheemulatedpicture,createdasspecifiedabove.Afterthepicture,printoneblankline.

SampleInput

2010

LINE321110

LINE310112

LINE20383

TEXT68TEST

LINE1911910

LINE1710171

LINE1611610

LINE136206

CLEAR205157

LINE1811810

TEXT1210NICEPICTURE

POINT11

POINT32

PRINT

11

POINT11

CLEAR1111

PRINT

33

LINE2123

LINE1232

LINE2321

LINE3212

LINE2123

LINE1232

PRINT

00

SampleOutput

+--------------------+

|o|||||

|*/|||||

|\--*-----++++-|

|\/|||||

|\/||

|x--||

|/\||

|/TES*|||||

|/\|||||

|/\NICE****U|

+--------------------+

+-+

||

+-+

+---+

|||

|-+-|

|||

+---+

 

【全文翻译】

日本绘图仪驱动程序

你工作的日本公司生产的绘图设备,能画很好的图。

为了支持不具有特殊硬件的客户,你被要求写一个仿真驱动模拟工作的绘图和打印的图像在计算机屏幕上。

绘图仪驱动一个包括几个绘图命令简单的语言:

POINTxy--在xy处写一个'o'。

TEXTxytxt--从(x,y)开始,向右写入txt。

LINEx1y1x2y2–从(x1,y1)到(x2,y2)划线。

CLEARx1y1x2y2--清空矩形区域(用空格填充)。

PRINT--打印输出页并终止当前的工作。

仿真驱动程序使用几个ASCII码代表一副图,是一个基本单位的坐标系统。

左上角的字坐标(1,1)。

数据中的xy是以向右延伸为x,向下延伸为y。

特殊命令模拟如下:

点:

司机把小写字母“o”放在指定坐标。

文字:

表示一个单一的文本行,第一个字是定位在给定坐标和文字总是向右的。

线:

模拟两点之间的直线。

该线是由以下字符中的一个组成:

破折号(“-”),管(“|”),斜杠(“/”),或反斜杠(“\”),根据其方向。

明确:

驱动程序在适当的矩形区域的空间,包括行和列的边界。

打印:

此命令使驱动程序打印的图片周围有一个漂亮的框架由加(“+”),负(“-”),和管(“|”)字组成。

如果一个格子被填了多次,按照如下规则。

如果多次填充的都一样,不变。

如果只有填充的只有'-'和'|',变为'+'。

如果填充的只有'\'和'/',变为小写'x'。

其他情况一律变为'*'。

在脚本放进驱动程序之前,这是检查一个拒绝一切无效命令的特殊预处理。

因此,你可以假设所有页面范围内的坐标。

此外,在命令行,这两点都是不同的,线是严格垂直,水平,或在45°角的轴。

没有任何假设的相对位置的点与线和明确的命令。

该文本在文本命令总是只由大写字母和数字。

此外,在命令行,这两点都是不同的,线是严格垂直,水平,或与轴成45°角。

没有任何假设的点与线在相对位置有明确的命令。

该文本在文本命令中总是只由大写字母和数字组成。

输入

输入由多个脚本组成。

每个脚本开头是一行包括2个整数x与y。

分隔空间,1<=×,γ=75。

这些数字在页面有指定尺寸。

每一条线都包含一个以上的命令。

命令总是大写,命令参数是一个个分离的空间。

打印命令总是脚本的最后命令。

在打印命令后,一个新的脚本开始了。

输入2个零时脚本终止。

输出

对每个脚本,输出模拟图像,作为上述指定。

在图像后,打印一个空行。

【算法分析】

题目:

JapanPlotterDriver

提交语言:

C++

运行时间:

0ms

运行内存:

184KB

#include

#include

#defineMAXSIZE80

charmap[MAXSIZE][MAXSIZE];

intsizex,sizey;

voidsetpoint(intx,inty,charc){

if(map[y][x]=='')map[y][x]=c;

elseif(map[y][x]==c)return;

elseif((map[y][x]=='-'||map[y][x]=='+'||map[y][x]=='|')&&

(c=='-'||c=='+'||c=='|'))map[y][x]='+';

elseif((map[y][x]=='/'||map[y][x]=='x'||map[y][x]=='\\')&&

(c=='/'||c=='\\'||c=='x'))map[y][x]='x';

elsemap[y][x]='*';

}

voidline(void){

intx1,x2,y1,y2,i;

scanf("%d%d%d%d",&x1,&y1,&x2,&y2);

if(x1==x2){

if(y1>y2){

i=y1;

y1=y2;

y2=i;

}

for(i=y1;i<=y2;++i)setpoint(x1,i,'|');

}elseif(y1==y2){

if(x1>x2){

i=x1;

x1=x2;

x2=i;

}

for(i=x1;i<=x2;++i)setpoint(i,y1,'-');

}elseif(x2-x1==y2-y1){

if(x1>x2){

i=x1;

x1=x2;

x2=i;

}

if(y1>y2){

i=y1;

y1=y2;

y2=i;

}

while(x1<=x2){

setpoint(x1,y1,'\\');

++x1;++y1;

}

}elseif(x2-x1+y2-y1==0){

if(x1>x2){

i=x1;

x1=x2;

x2=i;

}

if(y1>y2){

i=y1;

y1=y2;

y2=i;

}

while(x1<=x2){

setpoint(x1,y2,'/');

++x1;--y2;

}

}

}

voidpoint(void){

intx,y;

scanf("%d%d",&x,&y);

setpoint(x,y,'o');

}

voidtext(void){

intx,y,i;

charstr[1023];

scanf("%d%d%s",&x,&y,str);

for(i=0;str[i]&&i+x<=sizex;++i)setpoint(i+x,y,str[i]);

}

voidclear(void){

intx1,x2,y1,y2,i,j;

scanf("%d%d%d%d",&x1,&y1,&x2,&y2);

if(x1>x2){

i=x1;

x1=x2;

x2=i;

}

if(y1>y2){

i=y1;

y1=y2;

y2=i;

}

for(i=y1;i<=y2;++i)for(j=x1;j<=x2;++j)map[i][j]='';

}

voidprint(void){

inti,j;

printf("+");

for(i=1;i<=sizex;++i)printf("-");

printf("+\n");

for(i=1;i<=sizey;++i){

printf("|");

for(j=1;j<=sizex;++j)putchar(map[i][j]);

printf("|\n");

}

printf("+");

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

当前位置:首页 > 农林牧渔 > 林学

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

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