1008. Elevator
来源:互联网 发布:java infinity 编辑:程序博客网 时间:2024/05/12 00:39
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.
#include <stdio.h>#include <stdlib.h>int main (){ int n; scanf("%d",&n); int * num=new int[n]; for (int i=0;i<n;i++) scanf("%d",num+i); int sum=0; sum+=6*num[0]+5; for (int i=1;i<n;i++) { if(num[i]>num[i-1]) sum+=6*(num[i]-num[i-1])+5; else if(num[i]<num[i-1]) sum+=4*(num[i-1]-num[i])+5; else sum+=5; } printf("%d\n",sum); system("pause"); return 0; }
- 1008. Elevator
- 1008. Elevator
- 1008.Elevator
- 1008. Elevator
- 1008. Elevator
- 1008.Elevator
- 1008. Elevator
- 1008. Elevator
- 1008. Elevator
- 1008. Elevator
- 1008. Elevator
- 1008. Elevator
- 1008.Elevator
- 1008. Elevator (20)
- zju-pat 1008.Elevator
- 1008. Elevator (20)-PAT
- 【PAT】1008. Elevator (20)
- 1008. Elevator (20)
- Instruments使用技巧
- 16.HCNA-HNTD——STP原理与配置
- 萦绕在爱情深处最细微的感伤
- [C/C++]_[中级]_[数据地址对齐]
- 基础算法之动态规划
- 1008. Elevator
- how to install splint
- 假期总结
- ubuntu14.04 开机自动运行应用程序
- Qt版双人俄罗斯方块游戏
- POJ 2251-Dungeon Master
- RHEL/CentOS 7.x如何启动/关闭、启用/禁用服务? 修改系统运行级别
- 在jstl标签中forEach标签遍历Map
- 【codeforces】Codeforces Round #291 (Div. 2) 题解