题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1008
典型水题,第一次居然wa了,没考虑停在同一层也要算等待时间
题目大意
电梯上升一层要6秒,下降一层4秒,在那一层要停5秒,计算总时间
#include<iostream>
using namespace std;
int main()
{
int n;
int up=6,down=4,stay=5;
int before,now,time;
while(cin>>n,n)
{
time=0;before=0;
while(n--)
{
cin>>now;
if(now>before)
{
time+=(now-before)*up+stay;
before=now;
}
else if(now<before)
{
time+=(before-now)*down+stay;
before=now;
}
else time+=stay;//第一次这里没有考虑
}
cout<<time<<endl;
}
return 0;
}