HDU 1008电梯问题
2017-07-23 11:03
344 查看
Elevator
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 73522 Accepted Submission(s): 40461
Problem Description
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
There are multiple test cases. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100. A test case with N = 0 denotes the end of input. This test case is not to be processed.
Output
Print the total time on a single line for each test case.
Sample Input
1 2
3 2 3 1
0
Sample Output
17
41
思路
1、题目比较水,秒过。大概题意:就是说现在有个升降机,上升一层就要花6秒时间,到了目标楼层后会停留5秒时间,下降一层要花4秒时间,你一开始现在在0层,OJ提供你楼层信息,你计算出整个过程所花费的时间。
2、注意一点就是每行第一个数据代表之后有几组数据。并非算做楼层的
C++解法(OJ C++)
#include <iostream> using namespace std; int main() { int a[101]={0}; while(cin>>a[0]) { int end=0; int begin=0; int total=0; int count=1; if(a[0]==0) break; for(int i=1;i<=a[0];i++) { cin>>a[i]; count++; } for(int i=1;i<count;) { end=a[i]; 4000 if(end-begin>0) { total+=((end-begin)*6+5); i++; begin=a[i-1]; } else { total+=((begin-end)*4+5); i++; begin=a[i-1]; } } cout<<total<<endl; } return 0; }
相关文章推荐
- HDU_1008 Elevator(电梯)
- 杭电acm——1008电梯问题
- HDU 6052 2017 Multi-University Training Contest - Team 2 1008 To My Boyfriend:计数问题
- 1008电梯问题
- hdu1584 A strange lift (电梯最短路径问题)
- 九度1008&&HDU - 3790:最短路径问题 (最短路径dijkstra)
- HDU 电梯题:(Problem ID:1008)
- 1008:Elevator (电梯)问题
- 杭电ACM ——>HDU-1008电梯
- PAT程序设计考题——甲级1008(Elevator电梯时间计算问题)
- HDU 1008 电梯( 水题)
- hdu 6108 小C的倍数问题(同余定理)
- hdu 1008 Elevator
- HDU 6108 小C的倍数问题 【数学】 (2017"百度之星"程序设计大赛 - 初赛(A))
- 【HDU 1198】Farm Irrigation(字符串拼接/类油田问题/DFS)
- 【HDU】-2553-N皇后问题(DFS)
- HDU 1712 分组背包问题
- 九度1008:最短路径问题(Dijkstra)
- HDU 1754 I Hate It 线段树点修改问题
- hdu 3790 最短路径问题