看奥特曼入迷了,忘了写题解复盘
这个题以及后面会遇到的很多排队等待问题一样,是很麻烦的分析题。
我在2020年月底刚开始接触时,学习了其他前辈遍历时间根据情况分析的方法,感到十分麻烦,这一次我按照其他前辈关于入队操作,按人分析的方法,感觉思路更加清晰(模拟m行n列插入顾客的方式)。
注解见代码
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll n,m, k, q;
struct node
{
ll poptime, endtime;
queue<ll> q;
};
int main(void)
{
cin>>n>>m>>k>>q;
vector<ll> time(k + 1);
vector<bool> sorry(k + 1, false);
vector<node> window(n + 1);
vector<ll> result(k + 1);
ll index = 1;
for (ll i = 1; i <= k; ++i) {cin>>time[i];}
for (ll i = 1; i <= m; ++i)
{
for (ll j = 1; j <= n; ++j)
{
if (index <= k)
{
window[j].q.push(time[index]);
if (window[j].endtime >= 540) {sorry[index] = true;}
window[j].endtime += time[index];
if (i == 1) {window[j].poptime = window[j].endtime;}
result[index] = window[j].endtime;
index++;
}
}
}
while (index <= k)
{
ll tmpwindow = 1, tmptime = window[1].poptime;
for (ll i = 2; i <= n; ++i)
{
if (window[i].poptime < tmptime) {tmptime = window[i].poptime; tmpwindow = i;}
}
window[tmpwindow].q.pop();
window[tmpwindow].q.push(time[index]);
if (window[tmpwindow].endtime >= 540) {sorry[index] = true;}
window[tmpwindow].endtime += time[index];
window[tmpwindow].poptime += window[tmpwindow].q.front();
result[index] = window[tmpwindow].endtime;
index++;
}
ll id;
while (q--)
{
cin>>id;
if (sorry[id]) {printf("Sorry\n");}
else {printf("%02d:%02d\n", (result[id] + 480) / 60, (result[id] + 480) % 60);}
}
return 0;
}
睡了睡了
|