点击打开链接 密码:syuct
Elevator
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 3 Accepted Submission(s) : 3
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
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 2 3 2 3 1 0
Sample Output
17 41
水题
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int n;
int a[110];
int pos,sum;
while(scanf("%d",&n),n)
{
pos=0;
sum=0;
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
if(a[i]>pos)
{
sum+=6*(a[i]-pos)+5;
}
else
sum+=4*(pos-a[i])+5;
pos=a[i];
//printf("##%d\n",sum);
}
printf("%d\n",sum);
}
return 0;
}
本文介绍了一道关于电梯路径优化的问题,电梯需按指定楼层顺序停靠,计算完成所有请求所需的最短时间。该问题考虑了电梯上下楼的时间成本及在各楼层停留的时间。
1095

被折叠的 条评论
为什么被折叠?



