简单模拟,注意并不是完全按照FIFO的顺序。比如第i个人的id为k,那么就算第i+1人的id不为k,也会检查他后续的排队人是否有id为k的。
#include <cstdio>
#include <cstring>
#include <cstdlib> #define MAXN 1005 typedef struct {
int tt;
int id;
int num;
int ans;
} need_st; need_st needs[MAXN]; int main() {
int t, n, k, m, T;
int i, j, hh, mm, tt, tmp; scanf("%d", &T);
while (T--) {
scanf("%d%d%d%d", &n,&t,&k,&m);
for (i=; i<m; ++i) {
scanf("%d:%d %d %d", &hh, &mm, &needs[i].id, &needs[i].num);
needs[i].tt = *hh+mm;
}
tt = ;
for (i=; i<m; ++i) {
if (needs[i].num == )
continue;
if (tt < needs[i].tt)
tt = needs[i].tt;
tmp = needs[i].num%k;
tt += needs[i].num/k*t;
if (tmp > ) {
for (j=i+; j<m&&needs[j].tt<=tt; ++j) {
if (needs[j].id == needs[i].id) {
if (needs[j].num+tmp > k) {
needs[j].num -= (k-tmp);
break;
} else {
tmp += needs[j].num;
needs[j].num = ;
needs[j].ans = tt+t;
}
}
}
tt += t;
}
needs[i].ans = tt;
}
for (i=; i<m; ++i)
printf("%02d:%02d\n", needs[i].ans/%, needs[i].ans%);
if (T)
printf("\n");
} return ;
}