B

来源:互联网 发布:真三国无双6 知乎 编辑:程序博客网 时间:2024/04/30 06:21
B - Elevator
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
Submit Status Practice HDU 1008

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. 
 

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
这个题注意题意,还要注意 同层时也要计算时间,注意大于100的后果。。。。
#include<stdio.h>int main(){int n;while(scanf("%d",&n)!=EOF&&n!=0&&n<100){int a[n];for(int i=0;i<n;i++){scanf("%d",&a[i]);if(a[i]>=100)return 0;}int shi=0,sum=0;for(int i=0;i<n;i++){if(a[i]>shi){sum=sum+(a[i]-shi)*6+5;shi=a[i];}elseif(a[i]<shi){sum=sum+(shi-a[i])*4+5;shi=a[i];}elsesum=sum+5;}printf("%d\n",sum);}return 0; }