原题地址
https://www.patest.cn/contests/pat-a-practise/1008
题意:给出一组电梯调度的序列,已知上升一层耗时6秒,下降一层耗时4秒,每次停留5秒,求总耗时。
解题思路
觉得不应该放在PAT甲级题目里,因为实在没有看到考点。
直接模拟计数就可以了。
AC代码
#include <iostream>
using namespace std;
int main()
{
int n, next;
cin >> n;
int now = 0, total = 0;
for (int i = 0; i<n; ++i)
{
cin >> next;
if (next > now)
total += 6*(next - now) + 5;
else
total += 4*(now - next) + 5;
now = next;
}
cout << total << endl;
return 0;
}