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 ...
随机推荐
- E - 小晴天老师系列——我有一个数列!
E - 小晴天老师系列——我有一个数列! Time Limit: 20000/10000MS (Java/Others) Memory Limit: 128000/64000KB (Java/O ...
- 比较全的 C# 操作 Word的代码
using System;using System.Collections.Generic;using System.Text;using Microsoft.Office.Interop.Word; ...
- 关于LCD的分屏与切屏 Tearing effect
详细文档(带图片):http://download.csdn.net/detail/xuehui869/5268852 1.LCM之Fmark功能 http://blog.csdn.net/zhand ...
- [笔记]Practical Lessons from Predicting Clicks on Ads at Facebook
ABSTRACT 这篇paper中作者结合GBDT和LR,取得了很好的效果,比单个模型的效果高出3%.随后作者研究了对整体预测系统产生影响的几个因素,发现Feature+Model的贡献程度最大,而其 ...
- linux中的 tar命令的 -C 参数,以及其它一些参数(转)
linux中的 tar命令的 -C 参数,以及其它一些参数 复制源:http://www.cnblogs.com/li-hao/archive/2011/10/03/2198480.htmltar命令 ...
- 依赖注入容器Autofac与MVC集成
Autofac是应用于.Net平台的依赖注入(DI,Dependency Injection)容器,具有贴近.契合C#语言的特点.随着应用系统的日益庞大与复杂,使用Autofac容器来管理组件之间的关 ...
- Java 环境搭建的一些问题
1.http://www.eclipse.org/webtools/ eclipse 官网,SE.EE方向是两个不同eclipse 2.tomcat 对eclipse来说是一个插件,需要额外下载 T ...
- javascript: 字符串拼接有问题
点击某个链接,出现js错误:Uncaught SyntaxError: Unexpected token ILLEGAL 原因: $str .= sprintf('   ...
- 控制器view的加载顺序initWithNibName >>> viewDidLoad >>> viewWillAppear >>> viewDidAppear
-(void)viewWillAppear:(BOOL)animated { self.navigationController.navigationBarHidden=NO;// 邓超界:放在wil ...
- Inno Setup入门(二)——修改安装过程中的图片
修改安装过程中的图片 一般编译之后,安装过程中出现在左边图片是是下图这个样子的: 其实也可以修改它,只需要在setup段中作一点稍微的修改,加一行代码即可: [setup] AppName=Test ...