原题地址
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;
}

本文针对PAT甲级赛中的一道电梯调度题目进行了解答。题目要求根据电梯运行序列计算总耗时,通过直接模拟的方式实现,考虑了上下楼层的时间消耗及停层等待时间。
434

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



