PAT(甲级)1008
2015-09-23 16:19
501 查看
1008. Elevator (20)
时间限制400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue
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 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. The elevator will stay for 5 seconds at each stop.
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.
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.
Output Specification:
For each test case, print the total time on a single line.
Sample Input:
3 2 3 1
Sample Output:
41
#include <iostream>
using namespace std;
int main()
{
int N,number0,number1,time_stop,time_total=0;
cin >>N;
time_stop = 5*N;
number0=0;
while(N){
cin >>number1;
if(number1>number0)
time_total +=6*(number1-number0);
else
time_total +=4*(number0-number1);
number0 =number1;
N--;
}
time_total +=time_stop;
cout <<time_total <<endl;
return 0;
}
相关文章推荐
- Spring中注解的使用
- apue.h头文件的配置
- Android 应用程序之间内容分享详解(一)
- iOS开发——枚举类型和闭包
- 如果你还在用STM32F103,那么你OUT了
- 架构设计的常用思想
- Retrofit学习笔记(一)
- solr 如何实现精确查询
- Android软键盘弹出将底部栏顶上去并不会挤压界面
- 华为机试测试- 求有序数组中最长的等差序列
- Unity3D之Mecanim动画系统学习笔记(七):IK(反向动力学)动画
- 解决arm92410下载程序进去出现
- NSMutableArray替换对象
- Spring中关于bean的继承
- C++序列化方法 参考google protobuf
- oracle 查询表结构
- Android应用如何支持屏幕多尺寸多分辨率问题
- css选择器指定元素中第几个子元素
- LintCode Search Range in Binary Search Tree
- Configure iSCSI Target on RHEL7