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 ...
随机推荐
- python--zeros函数和ones函数
使用numpy.zeros,numpy.ones,numpy.eye等方法可以构造特定的矩阵 例如: 代码如下: >>>from numpy import * >>> ...
- js继承实现
JS实现继承可以分为:对象冒充和原型链继承 其中对象冒充又包括:临时变量,call 和 apply 临时变量方法: function Person(name,sex){ this.name = nam ...
- iOS学习笔记(01) - 泛型
决定新开一坑,在不断学习的同时分享自己的学习历程给大家,既是对自己学习的记录,又希望能对大家提供些微的帮助. 这一篇文章主要来介绍泛型的意义.使用与声明方法等. 1.泛型:限制类型 1.1.泛型使用场 ...
- java启动子进程以及进程通信
1.利用进程的管道通信传输流 2.子进程没有控制台,正常测试的时候也是没办法看到子进程的输出的,需要传到主线程 3.测试主进程传参给子进程再传回来 4.父进程启动子进程只要执行runtime.exec ...
- 11--Python 备份文件程序
最近看了下<A Byte of Python>, 看见一个非常有意思的程序,用python进行文件行备份的练习程序, 自己在机器上敲代码运行了一遍,结果出现了一个小问题,路径出错--&qu ...
- HDU 5773 The All-purpose Zero
这题想了1个多小时想不出来...方法真是精妙... 官方题解:0可以转化成任意整数,包括负数,显然求LIS时尽量把0都放进去必定是正确的.因此我们可以把0拿出来,对剩下 的做O(nlogn)的LIS, ...
- hdu_1513_Palindrome(LCS+滚动数组)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1513 题意:给你一个字符串,问你最少插入多少个字符使其为回文字符. 题解:将字符串倒着保存,然后求一下 ...
- hdu_4826_Labyrinth_2014百度之星(dp)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4826 题意:中文题,不解释 题解:dp搞,第一列只能从上往下走,所以先算出第一列的dp数组,然后开两个 ...
- golang vs java
http://programmers.stackexchange.com/questions/83780/how-fast-can-go-go In terms of language design, ...
- DefaultHttpClient is deprecated 【Api 弃用]】
最近在使用Apache的httpclient的时候,maven引用了最新版本4.3,发现Idea提示DefaultHttpClient等常用的类已经不推荐使用了,之前在使用4.2.3版本的时候,还没有 ...