HDU1008 Elevator

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1008

#include <iostream>

using namespace std;

int main(int argc, char *argv[])

{

int n,curLev,desLev,sumTime,tmp;

while(cin>>n&&n!=0)

{

curLev = 0;//初始层为0

sumTime = 0;

for(int i=0;i<n;++i)

{

cin>>desLev;//目标层

tmp = desLev-curLev;

if(tmp>0)

{//上楼

sumTime += tmp*6+5;

}

else

{//下楼

tmp = -tmp;

sumTime += tmp*4+5;

}

curLev = desLev;//修改当前所在层

}

cout<<sumTime<<endl;

}

return 0;

}

你可能感兴趣的:(HDU)