题目地址: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;

}

相关文章:

  • 2022-01-10
  • 2021-09-06
  • 2021-07-09
  • 2021-08-24
  • 2022-12-23
  • 2022-01-14
  • 2021-05-24
猜你喜欢
  • 2022-12-23
  • 2021-07-03
  • 2021-04-22
  • 2021-06-27
相关资源
相似解决方案