hdu 1008 Elevator 的解题报告

链接 :http://acm.hdu.edu.cn/showproblem.php?pid=1008

本题为一道简单的数学题没什么难的 ;但还是要注意

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.
 

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
1 #include<stdio.h>
2  int main()
3 {
4 int N,i;
5
6 while( scanf( "%d",&N )&&N>0 ){
7 int b=0,e=0,s=0;
8 for( i=0;i<N;++i ){
9 scanf( "%d",&e );
10 s+=5;
11 if( e>b )
12 s+=(e-b)*6;
13 else
14 s+=(b-e)*4;
15 b=e;//最开始写在下面虽然测试数据能过却一直WA杯具啊;后来发现测试数据全是2个数
16 }
17 //b=e;
18 printf( "%d\n",s );
19 }
20 }
posted @ 2011-03-29 22:08  淡墨æ末央  阅读(281)  评论(0编辑  收藏  举报