1008. Elevator (20)
来源:互联网 发布:科比09年体测数据 编辑:程序博客网 时间:2024/05/02 04:16
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 1Sample Output:
41
#include <iostream>#include <vector>#include <stack>#include <queue>#include <deque>#include <cstring>#include <string>#include <vector>#include <map>#include <algorithm>#include <functional>#include <fstream>using namespace std;#define UP (6)#define DOWN (4)#define STOP (5)int N;queue<int> q;int main(){int sumtime = 0;int nowfloor = 0;//fstream cin("F://max.txt");cin >> N;for(int i = 0;i < N;i++){int t;cin >> t;q.push(t);}while(!q.empty()){int des = q.front();q.pop();if(des > nowfloor){sumtime += (des - nowfloor)*UP + STOP;}else if(des < nowfloor){sumtime += (nowfloor - des)*DOWN + STOP;}else{sumtime += STOP;}nowfloor = des;}cout << sumtime;system("pause");return 0;}
- 1008. Elevator (20)
- 1008. Elevator (20)-PAT
- 【PAT】1008. Elevator (20)
- 1008. Elevator (20)
- 1008. Elevator (20)
- 1008. Elevator (20)
- PAT 1008. Elevator (20)
- 1008. Elevator (20)
- 1008. Elevator (20)
- PAT 1008. Elevator (20)
- 1008. Elevator (20)
- 1008. Elevator (20)
- 1008. Elevator (20)
- 1008. Elevator (20)
- 1008. Elevator (20)
- 1008. Elevator (20)
- 1008. Elevator (20)
- 1008. Elevator (20)
- URL::to() 与 URL::toRoute()
- 第4周项目5-循环双链表应用
- Servlet入门之HelloWorld
- 1007. Maximum Subsequence Sum (25)
- HDU5492 Find a path【DP】
- 1008. Elevator (20)
- Linux Shell学习笔记4:使用Linux环境变量
- 典型关联分析CCA(canonical correlation analysis)
- 网络方面的面试题
- [Cpp]去掉字符串空白2
- 大端对齐和小段对齐
- 全排列字典序与序号的一一对应关系 康托展开 perm2num num2 perm
- 1009. Product of Polynomials (25)
- Hive+mySql遇到的问题和解决办法