题目描述:
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.
大致思路:
就是一个简单的模拟,坐电梯,每层停留和上升有一个时间,注意一点细节就可以了。
代码:
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.
大致思路:
就是一个简单的模拟,坐电梯,每层停留和上升有一个时间,注意一点细节就可以了。
代码:
#include<stdio.h>
#include<string.h>
int main()
{
int n,i,tmp,floor[2000];
long time;
while (scanf("%d",&n)!=EOF)
{
memset(floor,0,sizeof(floor));
time=0;
for (i=1;i<=n;i++)
{
scanf("%d",&floor[i]);
tmp=floor[i]-floor[i-1];
if (tmp>0) time+=tmp*6+5;
if (tmp<0) time+=-tmp*4+5;
if (tmp==0) time+=5;
}
if (n!=0) printf("%ld\n",time);
}
}