银行排队问题之单队列多窗口服务 (25 分)

#include<bits/stdc++.h>
using namespace std;
struct Customers {
    int arrived;
    int need;
    int wait;
};
int counter_time[10] = {0};
int counter_serve[10] = {0};
int main() {
    vector<Customers> customers;//用队列,数组也可以
    int n, k;
    cin>>n;//顾客数
    for(int i = 0; i < n; i++) {
        Customers t;
        cin>>t.arrived>>t.need;
        if(t.need>60) t.need = 60;
        customers.push_back(t);
    }
    cin>>k;//窗口数
    for(int i = 0; i < n; i++) 
    {
        int choose = 0;
        for (int j = 0; j < k; j++)
        {
            if (counter_time[choose] > counter_time[j])//寻找最小时间
                choose = j;
            if (customers[i].arrived >= counter_time[choose])
                break;
        }
        if (customers[i].arrived >= counter_time[choose])
        {
            counter_time[choose] = customers[i].arrived + customers[i].need;
            customers[i].wait = 0;
        }
        else
        {
            customers[i].wait = counter_time[choose] - customers[i].arrived;
            counter_time[choose] += customers[i].need;//更新窗口等待时间
        }
        counter_serve[choose]++;//窗口服务总人数
    }
    double sum = 0;
    double longest_wait = 0;
    double longest_complete = 0;
    for(int i = 0; i < n; i++) {
        sum += customers[i].wait;
        if(customers[i].wait > longest_wait) longest_wait = customers[i].wait;
    }
    for(int i = 0; i < k; i++) {
        if(counter_time[i] > longest_complete) longest_complete = counter_time[i];
    }
    printf("%.1lf ",sum/n);
    cout<<longest_wait<<" "<<longest_complete<<endl;
    for(int i = 0; i < k; i++) {
        if(i != 0) cout<<" ";
        cout<<counter_serve[i];
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值