首页 > 代码库 > HDU 1008 Elevator

HDU 1008 Elevator

题解:简单模拟题。

#include<iostream>#include<stdio.h>#include<algorithm>using namespace std;int main(){    int n;    while(cin>> n && n){        int sum = 0;        int pre = 0, x;        for(int i=0; i<n; i++){                cin>>x;                if(x -pre>0){ //up                     sum += (x-pre)*6;                }else{ //down                    sum += (pre-x)*4;                }                sum+=5;                pre =x;            }            cout<<sum<<endl;        }    return 0;    }

  

HDU 1008 Elevator