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 ...
随机推荐
- C++ : 从栈和堆来理解C#中的值类型和引用类型
C++中并没有值类型和引用类型之说,标准变量或者自定义对象的存取默认是没有区别的.但如果深入地来看,就要了解C++中,管理数据的两大内存区域:栈和堆. 栈(stack)是类似于一个先进后出的抽屉.它的 ...
- Android 图片显示
一.Android手机显示图片 若R.G.B每种颜色使用一个字节(8bit)表示,每幅图像可以有1670万种颜色:若R.G.B每种颜色使用两个字节(16bit)表示,每幅图像可以有10的12次方种颜色 ...
- GRPC: set up..
get the grpc source file.. git clone https://github.com/grpc/grpc git submodule update --init --recu ...
- windows禅道环境搭建
zentao官网的几个网址 http://www.zentao.net/ http://www.zentao.net/article-view-79863.html 搭建环境需要下载两个文件 1) ...
- QC使用中问题点汇总
QC 使用中问题点汇总,包括以下四个方面: 1.不兼容IE7,IE8的问题(服务器端设置) 2.无法在Win 7下正常下载页面(客户端设置) 3.在QC中填写中文内容后无法正常提交到数据库(客户端设置 ...
- VBS基础篇 - 循环语句(4) - For Each...Next
VBS基础篇 - 循环语句(4) - For Each...Next For Each...Next 循环与 For...Next 循环类似.For Each...Next 不是将语句运行指定的次 ...
- hdu_5805_NanoApe Loves Sequence(xjb搞)
题目链接:hdu_5805_NanoApe Loves Sequence 题意: 给你n个数,现在要删一个数,删每个数的概率是一样的,现在问你删一个值后的相邻数绝对值最大差的期望是多少,因为担心精度误 ...
- HDU2502:月之数
Problem Description 当寒月还在读大一的时候,他在一本武林秘籍中(据后来考证,估计是计算机基础,狂汗-ing),发现了神奇的二进制数. 如果一个正整数m表示成二进制,它的位数为n(不 ...
- 访问nginx-php页面的时候 报access denied.
访问页面的时候出现这个时access denied 只需到/usr/local/php/etc/php.ini中修改一下 把这个注释掉 ;open_basedir = 把这个值赋值为1 cgi.f ...
- DataGirdView 编辑项时的验证
dgvConfig.DataSource = CreateTable(); dgvConfig.Columns["编号"].ReadOnly = true; //只读 dgvCon ...