队列模拟:
遇到第一个问题是id的确定,直接余n并不是窗口的位置,因为可能正好余数为0
窗口需要记录两个时间,一个是当前窗口第一个人服务完成时的时间和这个窗口的当前所有人服务完成的时间(用这个时间更新新来的人的时间)
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
const int maxn = 1e3 + 10;
struct node {
int finishtime, endtime;
queue<int>child;
}windows[30];
struct customer {
int endtime, p;
}a[maxn];
const int ST = 8 * 60, LT = 17 * 60;
int n, m, k, q;
int findmin()
{
int id = 1;
for (int i = 1; i <= n; i++)
{
if (windows[i].finishtime < windows[id].finishtime)
id = i;
}
return id;
}
int main()
{
scanf("%d%d%d%d", &n, &m, &k, &q);
for (int i = 1; i <= k; i++)scanf("%d", &a[i].p);
for (int i = 1; i <= n; i++)
windows[i].endtime=windows[i].finishtime = ST;
int cnt = 1;
while (cnt <= k)
{
if (cnt <= m*n)
{
int id = cnt%n==0 ? n : cnt%n;
windows[id].child.push(cnt);
if (windows[id].child.size() == 1)
{
windows[id].finishtime += a[cnt].p;
}
windows[id].endtime += a[cnt].p;
a[cnt].endtime = windows[id].endtime;
}
else
{
int id = findmin();
windows[id].child.pop();
windows[id].child.push(cnt);
int top = windows[id].child.front();
windows[id].finishtime += a[top].p;
windows[id].endtime += a[cnt].p;
a[cnt].endtime = windows[id].endtime;
}
cnt++;
}
for (int i = 0; i < q; i++)
{
int x;
scanf("%d", &x);
if (a[x].endtime - a[x].p >= LT)printf("Sorry\n");
else printf("%02d:%02d\n", a[x].endtime / 60, a[x].endtime % 60);
}
return 0;
}