假设银行有K个窗口提供服务,窗口前设一条黄线,所有顾客按到达时间在黄线后排成一条长龙。当有窗口空闲时,下一位顾客即去该窗口处理事务。当有多个窗口可选择时,假设顾客总是选择编号最小的窗口。
有些银行会给VIP客户以各种优惠服务,例如专门开辟VIP窗口。为了最大限度地利用资源,VIP窗口的服务机制定义为:当队列中没有VIP客户时,该窗口为普通顾客服务;当该窗口空闲并且队列中有VIP客户在等待时,排在最前面的VIP客户享受该窗口的服务。同时,当轮到某VIP客户出列时,若VIP窗口非空,该客户可以选择空闲的普通窗口;否则一定选择VIP窗口。
本题要求输出前来等待服务的N位顾客的平均等待时间、最长等待时间、最后完成时间,并且统计每个窗口服务了多少名顾客。
这题比较恶心,可以通过模拟时间的流逝来进行暴力求解
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 1010;
int n, m, v, window[maxn], cnt;
struct Custom {
int come, cost, vip, wait, finish;
}custom[maxn];
bool Time[20][maxn * 60], finish[maxn];
void solve() {
for (int t = 0; cnt < n; t++) {
if (Time[v][t] == false) {
for (int i = 1; i <= n; i++) {
if (finish[i] == true || custom[i].vip == 0) continue;
if (custom[i].come > t) break;
finish[i] = true;
custom[i].wait = t - custom[i].come;
custom[i].finish = t + custom[i].cost;
window[v]++;
cnt++;
for (int j = 0; j < custom[i].cost; j++) Time[v][t + j] = true;
break;
}
}
for (int i = 0; i < m; i++) {
if (Time[i][t] == true) continue;
for (int j = 1; j <= n; j++) {
if (finish[j] == true) continue;
if (custom[j].come > t) break;
finish[j] = true;
custom[j].wait = t - custom[j].come;
custom[j].finish = t + custom[j].cost;
window[i]++;
cnt++;
for (int k = 0; k < custom[j].cost; k++) Time[i][t + k] = true;
break;
}
}
}
int sumwait = 0, maxwait = 0, finishtime = 0;
for (int i = 1; i <= n; i++) {
sumwait += custom[i].wait, maxwait = max(maxwait, custom[i].wait), finishtime = max(finishtime, custom[i].finish);
}
printf("%.1lf %d %d\n", 1.0 * sumwait / n, maxwait, finishtime);
for (int i = 0; i < m; i++) printf("%d%c", window[i], i == m-1 ? '\n' : ' ');
}
int main() {
scanf("%d", &n); for (int i = 1; i <= n; i++) {
scanf("%d %d %d", &custom[i].come, &custom[i].cost, &custom[i].vip);
if (custom[i].cost > 60) custom[i].cost = 60;
custom[i].wait = custom[i].finish = 0;
}
scanf("%d %d", &m, &v);
memset(window, 0, sizeof(window));
memset(Time, false, sizeof(Time));
memset(finish, false, sizeof(finish));
cnt = 0;
solve();
return 0;
}