HDU1008
来源:互联网 发布:sql正则 编辑:程序博客网 时间:2024/06/05 00:50
Elevator
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 72129 Accepted Submission(s): 39670
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//电梯调度问题,上一个状态与下一个状态比较 要把在同一楼侧的情况考虑进去(切记)#include <iostream>#include <cstdio>#include <algorithm>using namespace std;int main(int argc, const char * argv[]) { int n,num[100]; while(scanf("%d",&n)&&n) { int time=0; num[0]=0; for(int i=1;i<=n;i++) scanf("%d",&num[i]); for(int i=1;i<=n;i++) { if(num[i]>num[i-1]) time+=6*(num[i]-num[i-1])+5; if(num[i]<num[i-1]) time+=(num[i-1]-num[i])*4+5; if(num[i]==num[i-1])//同一楼层 time+=5; } cout<<time<<endl; } return 0;}
阅读全文
0 0
- hdu1008
- hdu1008
- hdu1008
- hdu1008
- HDU1008
- HDU1008
- HDU1008
- hdu1008
- hdu1008
- HDU1008
- hdu1008
- HDU1008
- HDU1008
- HDU1008
- HDU1008
- HDU1008
- hdu1008
- HDU1008 Elevator
- Java基础应用之运算符(为新员工分配部门)
- codevs 1098 均分纸牌
- java 往frame或组件中添加监听事件无效
- HDU1005
- 淘淘商城系列——Solr的安装
- HDU1008
- 195.m1-读取本地数据
- HDU1012
- 196.m1-解析服务器请求的json数据
- 单例模式的应用场景
- 空间复杂度和时间度的概念
- 关于springmvc 中的Controller使用自动装配失败的解决方法
- 2017.03 JAVA 面试题 中高级
- VS2010 SP1 安装信息