hdu1008

Elevator

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

   1 /*written by czk*/
   2 #include <stdio.h>
   3 
   4 int main() {
   5     int n, i;
   6     while(scanf("%d", &n) != EOF) {
   7         int time = 0;
   8         int current = 0;
   9         int next;
  10         if(n == 0)
  11             break;
  12         for(i = 0; i < n; i++) {
  13             scanf("%d", &next);
  14             if(next > current)
  15                 time += (next - current) * 6 + 5;
  16             else
  17                 time += (current - next) * 4 + 5;
  18             current = next;
  19         }
  20         printf("%d\n", time);
  21     }
  22 }

hdu1008 (2008-06-01 13:56:59由czk编辑)