这题有个狗屎一样的测试点(4、5),题目没有说明17:00之前进入窗口服务的顾客在超时情况下任然会得到完整服务,比如16:59进入服务窗口,服务一个小时,17:59结束服务,那么17:59就是结果而非Sorry。
#include<cstdio>
#include<string>
#include<queue>
#include<map>
using namespace std;
#pragma warning(disable:4996)
const int allTime = 9 * 60;
void MinutesToTime(int minutes) {
//if (minutes > allTime)printf("Sorry\n");
//else {
int HH = 8 + minutes / 60;
int MM = minutes % 60;
printf("%02d:%02d\n", HH, MM);
//}
return;
}
struct customer {
int time;
int index;
bool flag;
customer() {}
customer(int time_, int index_, bool flag_) {
time = time_;
index = index_;
flag = flag_;
}
};
const int maxn = 1010;
struct window {
queue<customer*> customers;
}windows[maxn];
int N, M, K, Q;
queue<customer*> custs;
map<int, int> ans;
bool insert(customer* a) {
int min = windows[0].customers.size(), which_window = 0;
for (int i = 1; i < N; i++) {
if (windows[i].customers.size() < min) {
min = windows[i].customers.size();
which_window = i;
}
}
if (min >= M)return false;// is to delete end customer
windows[which_window].customers.push(a);
return true;
}
int time_now = 0;
int main() {
scanf("%d %d %d %d", &N, &M, &K, &Q);
if (N <= 0 || M <= 0) {
for (int i = 0; i < Q; i++)printf("Sorry\n");
return 0;
}
for (int i = 0; i < K; i++) {
int time;
scanf("%d", &time);
customer *a = new customer(time, i + 1, false);
custs.push(a);
}
int now = 0;
while (now < allTime) {
now++;
while (custs.size() > 0 && insert(custs.front())) {
custs.pop();
}
for (int i = 0; i < N; i++) {
if (windows[i].customers.size() <= 0)continue;
windows[i].customers.front()->time--;
windows[i].customers.front()->flag = true;
if (windows[i].customers.front()->time <= 0) {
int index = windows[i].customers.front()->index;
windows[i].customers.pop();
ans[index] = now;
}
}
}
for (int i = 0; i < N; i++) {
if (windows[i].customers.size() <= 0)continue;
if (windows[i].customers.front()->flag) {
now = allTime + windows[i].customers.front()->time;
int index = windows[i].customers.front()->index;
ans[index] = now;
}
}
for (int i = 0; i < Q; i++) {
int query = 0;
scanf("%d", &query);
if (ans.find(query) != ans.end()) {
MinutesToTime(ans[query]);
}
else {
printf("Sorry\n");
}
}
return 0;
}