题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1008
水题,主要是逻辑关系搞清楚!
2 using namespace std;
3 #include<iostream>
4 int move(int c, int n){
5 if(c < n) return (n-c)*6 + 5;
6 else return (c-n)*4 + 5;
7 }
8
9 int main()
10 {
11 int n, curfloor, nextfloor, time;
12 while(scanf("%d", &n)){
13 if(n == 0) break;
14 time = curfloor = 0;
15 while(n--){
16 scanf("%d", &nextfloor);
17 time += move(curfloor, nextfloor);
18 curfloor = nextfloor;
19 }
20 printf("%d\n", time);
21 }
22 return 0;
23 }
3 #include<iostream>
4 int move(int c, int n){
5 if(c < n) return (n-c)*6 + 5;
6 else return (c-n)*4 + 5;
7 }
8
9 int main()
10 {
11 int n, curfloor, nextfloor, time;
12 while(scanf("%d", &n)){
13 if(n == 0) break;
14 time = curfloor = 0;
15 while(n--){
16 scanf("%d", &nextfloor);
17 time += move(curfloor, nextfloor);
18 curfloor = nextfloor;
19 }
20 printf("%d\n", time);
21 }
22 return 0;
23 }