1121: Elevator
Time limit: 1 Sec Memory Limit: 128 MB
submission: 6764 Resolution: 4685
[state] [Discussion Board] [submit] [proposition man: admin]
topic describes
only one elevator in a high-rise building, when you when you press a number, the elevator will run to that level. Each elevator is known for an increase in layer 6 seconds, one drop takes four seconds, and in that the layer needs to stay for 5 seconds. N integers prior to a list of requirements, sequentially in response to the elevator, the elevator runs from 0 layer, and before the operation process does not return 0 layer.
Note that, if there are equal two adjacent integer representing the same layer to perform two different tasks, it can be understood as: the elevator has stopped 5 seconds time and someone was about to close the door key at the same level, but also open the door and elevator for 5 seconds.
Input
Input in two rows, the first row is a positive integer N (N <= 1000), representative of the residence times, N of the second row numbers which represent several floors sequentially stay.
Output
Output elevator time required to complete the task sequence, a separate line.
Sample input the Copy
. 3
2. 3. 1
Sample output the Copy
41 is
prompted to
lift up from layer 2 to layer 0 run time of 12 seconds for 5 seconds, then rise in the third layer, run time of 6 seconds, for 5 seconds, then drops to a first level, run time 8 seconds , for 5 seconds. Total 41 sec.
#include<stdio.h>
int Time(int n)
{
int i,num;
int time=0,h=0;
for(i=1;i<=n;i++)
{
scanf("%d",&num);
if(num>h)
{
time=time+(num-h)*6+5;
h=num;
}
else if(num==h)
{
time=time+5;
}
else
{
time=time+(h-num)*4+5;
h=num;
}
}
return(time);
}
int main()
{
int Time(int n);
int n;
scanf("%d",&n);
printf("%d\n",Time(n));
return 0;
}