PTA 7-6 银行排队问题之单队列多窗口加VIP服务

假设银行有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;
}


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值