PAT甲级1008. Elevator (20)(得了15分程序有错误)
2018-02-28 22:02
513 查看
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
提交代码
时间限制
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> #include <vector> using namespace std; int N; struct Node { int num; bool flag = false; }; int main() { int i, upTime = 0, downTime = 0, waitTime = 0; cin >> N; struct Node node[N+2]; vector <int> a; node[0].num = 0; node[0].flag = true; node[N+1].num = 0; node[N+1].flag = true; for (i = 1; i <= N; i++) { cin >> node[i].num; if (i == 1 || i == N) { node[i].flag = true; } if (node[i].num > node[i-1].num && node[i].num > node[i+1].num) { node[i].flag = true; } if (node[i].num < node[i-1].num && node[i].num < node[i+1].num) { node[i].flag = true; } } for (i = 0; i <= N+1; i++) { if (node[i].flag == true) { a.push_back(node[i].num); } } waitTime = N * 5; for (i = 1; i < a.size() - 1; i++) { if (a[i] > a[i-1]) { upTime += (a[i] - a[i-1]) * 6; } if (a[i] < a[i-1]) { downTime += (a[i-1] - a[i]) * 4; } } cout << upTime+downTime+waitTime; return 0; }
相关文章推荐
- PAT程序设计考题——甲级1008( elevator) C++实现
- 【PAT甲级】1008. Elevator (20)
- pat甲级1008. Elevator (20)
- pat甲级1008. Elevator (20)
- [PAT甲级]1008. Elevator (20)(求电梯运行时间)
- PAT甲级 1008.Elevator(20) 题目翻译与答案
- PAT甲级1008. Elevator (20)
- PAT甲级 1008. Elevator (20)
- 1008. Elevator (20)-PAT甲级真题
- PAT(甲级)1008. Elevator (20)
- 【PAT甲级】1008. Elevator (20)
- PAT TEST甲级1008. Elevator (20)
- PAT甲级-1008.Elevator (20)
- PAT程序设计考题——甲级1008(Elevator电梯时间计算问题)
- PAT甲级1008. Elevator (20)
- 【PAT甲级】【C++】1008. Elevator (20)
- PAT 甲级 1008. Elevator (20)
- PAT - 甲级 - 1008. Elevator (20)1008. Elevator (20)
- PAT甲级1008. Elevator(20)
- PAT甲级1008. Elevator (20)