PAT1008
1008. Elevator (20)
时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors
在我们城市最高的建筑只有一部电梯。一个请求的列表由N个正整数组成。这些数字代表
the elevator will stop, in specified order. It costs 6 seconds to move the elevator up one floor, and 4 seconds to move down one floor.
电梯在那一层将会停下,按指定的顺序。电梯移动上一层需要花费6秒,电梯下一层需要花费4秒。
The elevator will stay for 5 seconds at each stop.
电梯每一次停下的时候会停5秒。
For a given request list, you are to compute the total time spent to fulfill the requests on the list.
对于给出的列表,你要计算出执行这个请求总共花费的时间。
The elevator is on the 0th floor at the beginning and does not have to return to the ground floor when the requests are fulfilled.
电梯将会总第0层开始并且在执行请求的执行完成之后不需要返回地面这一层。
Input Specification:
Each input file contains one test case. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100.
每一个输入文件包含一个测试案例。每个案例包含一个正数N,之后有N个正数,所有输入的数都小于100
Output Specification:
For each test case, print the total time on a single line.
对于每一个测试案例,在一行打印出总共的时间。
Sample Input:
3 2 3 1
测试案例解释
2*6 + 5 = 17
1*6 + 5 = 11
2*4 + 5 = 13
17+11+13 = 41
Sample Output:
41
题目解析:
这道题目本身就超级简单,但是之所以还是要写,就是因为第一遍交我错了。
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm> using namespace std; int main()
{
int n;
int sum=,now=,temp=;
cin >> n;
while (n--)
{
cin>>temp;
if(temp > now)
sum += (temp-now)* + ;
else if(temp < now)
sum += (now-temp)* + ;
else
sum += ;
now=temp;
}
cout<<sum<<endl;
return ;
}
很多朋友都是直接就
if(temp > now) sum += (temp-now)* + ;
else sum += (now-temp)* + ;
然后就啥也不管的对了
我为啥要写那么多呢?
就是因为我错,是因为我考虑的还不够周全,当前后两个数一样的时候是应该加5秒的
虽然我觉得这非常不合理,在实际的电梯应该没有出现这样的情况
但是确实,如果不加这5秒就会错误
所以考虑事情还是需要把所有的情况都考虑在内
并且分析清楚,很多小题会忽视这个问题,在大题目上面暴露出来就完了
PAT1008的更多相关文章
- PAT1008:Elevator
1008. Elevator (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The highest ...
- pat1008. Elevator (20)
1008. Elevator (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The highest ...
随机推荐
- 20_学生选课数据库SQL语句练习题
一. 设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher).四个表的结构分别如表1-1的表(一)~表( ...
- elipse图标注解
Java中的访问修饰符(访问控制符)包括:public,protected,default,private.分别代表了不同的访问权限.如果省略,则被视为使用了默认的default作为访问修饰符.从字面 ...
- while循环与i--
int i = 5; while(i-- > 0){ System.out.println("i="+i); } 打印 ...
- linux手工笔记
一.vi编辑器常用命令: -------------------------------- •插入文字:I键A键 •退回命令模式:ESC •存盘:w •不存盘退出:q •存盘退出:wq •强制退出:q ...
- cmd 下登陆ftp及相关操作
cmd 下登陆ftp及相关操作 2011-08-09 20:34:28| 分类: 小技巧|字号 订阅 一.举例 假设FTP地址为“ 61.129.83.39”(大家试验的时候不要以这个FTP去试,应 ...
- shell脚本学习(二)
4.cat命令 1) cat -s 摆脱多余的空白行 2) cat -T 将制表符显示为^I 3) cat -n 显示行号 4) cat -b 跳过空白行,然后显示行号 ...
- OpenCV——运用于pixels war游戏
// The "Square Detector" program. // It loads several images sequentially and tries to fin ...
- 运维必备:Oracle自备份精简教程(linux及win)
Oracle在linux环境下的自动备份 1.自动导出及历史文件删除脚本 su - oracle<<EOF cd /db_backup/databak mv orabak*.* /db_b ...
- Activity竟然有两个onCreate方法,可别用错了
public class HomeDetailActivity { @Override protected void onCreate(@Nullable Bundle savedInstanceSt ...
- Linux下配置Nginx按天切割日志
Nginx由于轻巧和高效的设计风格,去掉了一些额外的功能,所以它不像apache那样有自动切割日志. 建立一个脚本文件,并保证这个文件有可执行的权限:1.建立一个文件/root/log.nginx.s ...