题目地址: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;
}
本文转自Phinecos(洞庭散人)博客园博客,原文链接:http://www.cnblogs.com/phinecos/archive/2007/12/23/1011835.html,如需转载请自行联系原作者