题目地址:
点此打开题目地址
题目:
Elevator
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 43034 Accepted Submission(s): 23608
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
大意和思路:这个题的思路比较简单,当上一层楼的时候,每上一层楼用6个小时,电梯在楼层停留5个小时,每下一层楼电梯用4个小时;计上下楼的顺序是啊【n】;n<100;如果是上楼,时间是(a[i]-a[i-1])*6+5;下楼是
(a[i]-a[i-1])*4+5;
代码:
#include<stdio.h>
int t(int a,int b)
{
return a>b?(a-b)*4+5:(b-a)*6+5;
}
main()
{
int i,j,k,m,n,T,a[110],time;
while(scanf("%d",&T)&&T)
{
for(i=0;i<T;i++)
scanf("%d",&a[i]);
time=0;
time+=t(0,a[0]);
for(i=1;i<T;i++)
time+=t(a[i-1],a[i]);
printf("%d\n",time);
}
}
本文探讨了电梯在完成一系列楼层停靠请求时的时间消耗计算,包括上行、下行的耗时及楼层停留时间,通过算法优化提升效率。
396

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



