Description
有一座电梯,它的性能如下:上升一层需要6秒钟,下降一层需要4秒钟,如果要让它停下,它会停5秒钟。现在告诉你它要按顺序到达然后停靠的N个楼层,求它需要的时间。电梯开始在0层,楼梯共有100层。
Input
第一行为N(N<=50),接下来的N行是它N个停靠的楼层。
Output
只有一行,为所需要的时间。
Sample Input
1 2 3 2 3 1
Sample Output
17 41
Source:#include < iostream >
using namespace std;
int T;
int a[ 51 ];
int N;
void time()
... {
for(int i=1;i<=N;i++)
...{
if(i==1) T+=6*a[i]+5;
else
...{
if(a[i]<a[i-1])
...{
T+=4*(a[i-1]-a[i])+5;
}
if(a[i]>a[i-1])
...{
T+=6*(a[i]-a[i-1])+5;
}
if(a[i]==a[i-1]) T+=5;
}
}
}
int main()
... {
cin>>N;
for(int i=1;i<=N;i++)
...{
cin>>a[i];
}
if(N==1&&a[N]==0)
...{
cout<<T;
exit(1);
}
time();
cout<<T<<endl;
}