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的更多相关文章

  1. PAT1008:Elevator

    1008. Elevator (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The highest ...

  2. pat1008. Elevator (20)

    1008. Elevator (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The highest ...

随机推荐

  1. A - LCM Challenge

    A - LCM Challenge Time Limit: 2000/1000MS (Java/Others)    Memory Limit: 128000/64000KB (Java/Others ...

  2. 表单提交是ajax提交,PC提交没问题但是手机提交就会一直跳到error,并且也没状态码一直是0

    真是被自己蠢死了button标签他会自动提交刷新页面 <form id="baoming_from"> <p>请填写您的个人信息</p> < ...

  3. mysql5.7.16安装

    系统:centOS6.5 mysql: 5.7.16 wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.16-linux-glib ...

  4. Dash:程序员的好帮手

    Dash 关于Dash是什么.有哪些功能以及该怎么使用,我想直接引用咖啡 生活 美女蛇,这位小伙伴整理的很详细,我这里只说一下Dash的破解方法. 破解 破解补丁下载:Dash3.x_Cracked ...

  5. 2016-11-10linux

    ---恢复内容开始---  新建用户natasha,uid为88,gid为6,备注信息为"master"   修改natasha用户的家目录为/Natasha    查看用户信息配 ...

  6. Spring框架--AOP编程

    2 手动实现AOP编程 AOP 面向切面的编程, AOP可以实现"业务代码"与"关注点代码"分离 // 保存一个用户 public void add(User ...

  7. Astyle编程语言格式化工具的说明

    1.工具->扩展和更新,搜astyle插件,下载安装重启,当前是2.0版本. 2.工具->选项->AStyle Formatter->Edit,填入下面的,点击save,确定. ...

  8. HDU 5828 Rikka with Sequence

    好久没写线段树了,这题作为一个回味.. 第一种操作的话,就是一个延迟标记. 第二种操作可以暴力更新下去,但是有一个优化,如果某区间内所有值都是一样的,或者最大值和最小值相差1,那么到此结束,不要继续往 ...

  9. lldpd-0.7.7代码解读(send_pdu部分)

    此文档是经过逆序推到出的,可能有错误之处,敬请指教,谢谢. 1)interfaces_update 更新一些接口信息 2)levent_iface_subscribe 该接口通过socket通信(非阻 ...

  10. Android实现Excel表格,且表格能左右、上下滑动

    1.自定义实现一个水平滚动控件HorizontalScrollView import android.content.Context; import android.util.AttributeSet ...