杭电1008-Elevator
来源:互联网 发布:mysql安装步骤 编辑:程序博客网 时间:2024/05/21 01:32
Elevator
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 53208 Accepted Submission(s): 29402
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.
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 23 2 3 10
Sample Output
1741
AC代码:
#include<cstdio>int main(){int a,n,i,b,t,time;while(scanf("%d",&n),n){time=0;t=0;time+=n*5;//停止用的时间for(i=0;i<n;i++){scanf("%d",&a);if(a>t) time+=(a-t)*6;//每次和前一个比较若是上楼,则一层加6 else time+=(t-a)*4;//下一层加4 t=a; } printf("%d\n",time); } return 0; }
0 0
- 杭电1008 Elevator
- 杭电1008 Elevator
- 杭电1008 Elevator
- Elevator 杭电1008
- 杭电 1008 Elevator
- 杭电1008 Elevator
- 杭电 1008 Elevator
- 杭电 1008 Elevator
- 杭电1008-Elevator
- 杭电 1008 Elevator
- 杭电1008 Elevator
- 杭电ACM 1008Elevator
- 杭电ACM-1008 Elevator
- 杭电ACM-1008-Elevator
- 杭电acm 1008 Elevator
- 杭电 ACM 1008:Elevator
- 杭电ACM 1008Elevator
- 杭电 HDOJ 1008 Elevator
- Servlet 的生命周期
- 如何根治安卓卡顿短板 三星这次有办法
- LaunchImage设置失败的可能原因之一
- 两个线程按顺序打印1~10
- iOS项目开发实战——使用UICollectionView实现瀑布流
- 杭电1008-Elevator
- webview实践
- Grunt入门
- 计数排序
- spring mvc 文件上传+本地预览+一次提交
- 进程、线程知识点随笔
- 测试用例的主要要素
- zTree
- Arm nandflash&norflash启动原理