电梯上升一层6秒,下降一层4秒,每层停留5秒
Sample Input:
3 2 3 1
Sample Output:
41
#include <iostream>
using namespace std;
int main()
{
int N;
cin>>N;
int current = 0;
int total = 0;
while (N--)
{
int a;
cin>>a;
if (a >= current)
{
total += (a - current) * 6 + 5;
current = a;
}
else
{
total += (current - a) * 4 + 5;
current = a;
}
}
cout<<total;
return 0;
}
本文详细阐述了电梯算法的应用,通过实例分析了如何利用算法解决电梯上升与下降的问题,并提供了相应的代码实现。其中包括输入输出样例及算法核心逻辑。
305

被折叠的 条评论
为什么被折叠?



