2012 年宁波市第 27 届中小学生计算机程序设计竞赛,宁波市第27届中小学生计算机程序设计竞赛复赛试题(小学组).pdf...

宁波市第 27 届中小学生计算机程序设计竞赛

复赛试题( 小学组 )

题目一览

试题名称 傻瓜电梯 数字替换 取珠子 猜数字

英文代号 dianti change pearl guess

程序名 dianti.pas/c/cpp change.pas/c/cpp pearl.pas/c/cpp guess.pas/c/cpp

输入文件名 dianti.in change.in pearl.in guess.in

输出文件名 dianti.out change.out pearl.out guess.out

内存限制 128 MB 128 MB 128 MB 128 MB

时限 1 秒 1 秒 1秒 1 秒

关于竞赛中不同语言使用限制的说明

一.关于使用 Pascal 语言与编译结果的说明

1 .对于 Pascal 语言的程序,当使用 IDE 和fpc 编译结果不一致时,以 fpc 的编译

结果为准。

2 .允许使用数学库 (uses math 子句 ) ,以及 ansistring 。但不允许使用编译开

关(最后测试时 pascal 的范围检查开关默认关闭: {$R-,Q-,S-} ),也不支持与优

化相关的选项。

3 .本次比赛允许使用 64 位整数类型: int64 或 qword 。

1. 傻瓜电梯( dianti )

题目描述

所谓傻瓜电梯指的是在响应用户请求时缺乏相应的 “智商”,在上升或下降的

过程中不 能把中途的乘客捎带入电梯,而只会严格按照用户发出请求的先后顺

序依次完成任务。

比如,原来电梯在 1 楼,首先 6 楼有一位乘客发出请求,要求由 6 楼乘坐到

10 楼去, 此时电梯马上会上去, 但在电梯上升到 3 楼时,另外一位乘客请求由 5

楼乘坐到 8 楼去,傻瓜电梯却不会在上升途中把 5 楼的乘客捎带上去,而只会先

把 6 楼的乘客送到 10 楼,然后 再下来把 5 搂的乘客送到 8 楼。

傻瓜电梯由 i 楼上升到 i+1 楼(或下降到 i-1 楼)的时间都是 3 秒,每到达

一个楼层, 不管进出乘客有多少, 也不管乘客只有进、 只有出或者进出电梯都有,

所耽搁的时间都是 6 秒。现在味味要根据傻瓜电梯接受到的 n 个用户请求,编程计

算傻瓜电梯把所有乘客送到目 标楼层时总共所需要的时间。

如果某批乘客到达目标楼层后,电梯没有马上要响应的请求,则电梯在前

一批乘客的目的地等待, 这个等待时间也需计入总花费时间。 直到下一批乘客发

出新请求,电梯才会从当前位置出发,前往下一批乘客的出发楼层。

输入

输入文件 dianti.in 第一行包含两个整数 x (1<=x<=100)和 n (1<=n<=100),

分别表示 傻瓜电梯开始所在的楼层和总共接收到的请求数目。 下面有 n 行,每行

包含 3 个整数,依次 表示该请求发出的时间、 乘客目前所在的楼层和将要去的目

标楼层。其中请求发出的时间以秒为时刻单位, 最大可能的值是 2000。如果某两

个请求的发出时间相同,则

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
C++源代码 注重类的交互 片段 #include using namespace std; #include "elevator.h" //Elevator class definition #include "person.h" //Person class definition #include "floor.h" //Floor class definition //constants that represent time required to travel //between floors and direction of the elevator const int Elevator::ELEVATOR_TRAVEL_TIME = 5; const int Elevator::UP = 0; const int Elevator::DOWN = 1; //constructor Elevator::Elevator( Floor &firstFloor, Floor &secondFloor) : elevatorButton( * this ), currentBuildingClockTime( 0 ), moving( false ), direction( UP ), currentFloor( Floor::FLOOR1 ), arrivalTime( 0 ), floor1NeedsService( false ), floor2NeedsService( false ), floor1Ref( firstFloor ), floor2Ref( secondFloor ), passengerPtr( 0 ) { cout << "elevator constrcuted" <<endl; }// end Elevator constructor //destructor Elevator::~Elevator() { delete passengerPtr; cout << "elevator destructed" << endl; }//end Elevator destructor //give time to elevator void Elevator::processTime( int time ) { currentBuildingClockTime = time; if ( moving ) //elevator is moving processPossibleArrival(); else processPossibleDeparture(); if ( !moving ) cout << "elevator at rest on floor " << currentFloor << endl; }// end function processTime // when elevator is moving, determine if it should stop void Elevator::processPossibleArrival() { //if elevator arrives at destination floor if ( currentBuildingClockTime == arrivalTime ) { currentFloor = ( currentFloor == Floor::FLOOR1 ? Floor::FLOOR2 : Floor::FLOOR1); //update current floor direction = ( currentFloor == Floor::FLOOR1 ? UP : DOWN ); //update direction cout << "elevator arrives on floor " << currentFloor <<endl; // process arrival at currentFloor arriveAtFloor( currentFloor == Floor::FLOOR1 ? floor1Ref : floor2Ref); return; }//end if //elevator still moving cout << "elevator moving " << ( direction == UP ? "UP" : "DOWN"

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值