pat 甲级 A1017 Queueing at Bank (25分)

题目链接:

https://pintia.cn/problem-sets/994805342720868352/problems/994805491530579968

 

题目大意:

模拟N名顾客去银行K个窗口排队。给出N名顾客的到达时间以及服务时间,因此是先到先服务,不难想到需要队列保存顾客信息,包括达到时间,以及服务时间。且假设每名顾客不会被服务超过1小时,要你计算出顾客的平均等待时间,下午5点之后达到的顾客不会被服务,同样也不会被记入平均等待时间中。

虽然和patA1014题意上有很多相似之处,比如我们可以将窗口中的长度在此题中视为1,但不同的是,此题给出了达到时间,即先来先服务,所以需要用队列保存达到银行的客户。

patA1014:https://blog.csdn.net/dutmathjc/article/details/105593474

 

参考代码:

#include <bits/stdc++.h>
using namespace std;
const int n = 111;
const int inf = 1000000000;
struct Customer{
    int cometime, servetime; //客户达到时间,以及服务时间。
}newcustomer;

vector<Customer> custom; //模拟队列。
int convert(int h, int m, int s){
    return 3600*h + 60*m + s;
}
bool cmp(Customer a, Customer b){   //用于对顾客达到时间排序
    return a.cometime < b.cometime;
}
int Endtime[n];
int main()
{
    int cnum, wnum, tottime = 0;
    int sttime = convert(8, 0, 0);
    int endtime = convert(17, 0, 0);
    scanf("%d %d", &cnum, &wnum);
    for(int i = 0; i < wnum; i++) Endtime[i] = sttime;   //没有用户,窗口的结束时间初始化为sttime。
    for(int i = 0; i < cnum; i++){  //将17点前(含17点)到达的顾客保存到custom中,用于计算平均等待时间
        int h, m, s, servetime;
        scanf("%d:%d:%d %d", &h, &m, &s, &servetime);
        int cometime = convert(h, m, s);
        if(cometime > endtime) continue; //如果超过17点到达的顾客,不计入计算。(不含17点)
        newcustomer.cometime = cometime;
        newcustomer.servetime = servetime < 60 ? servetime*60 : 3600;
        custom.push_back(newcustomer);  //将新客户加入。
    }
    sort(custom.begin(), custom.end(), cmp);
    for(int i = 0; i < custom.size(); i++){
        int idx = -1, minendtime = inf;    //选择当前最早结束服务的窗口
        for(int j = 0; j < wnum; j++){
            if(Endtime[j] < minendtime){
                minendtime = Endtime[j];
                idx = j;
            }
        }
        if(Endtime[idx] <= custom[i].cometime){  //当顾客到达时,窗口已空,则无需排队。
            Endtime[idx] = custom[i].cometime + custom[i].servetime;
        }else{
            tottime += (Endtime[idx] - custom[i].cometime);
            Endtime[idx] += custom[i].servetime;
        }
    }
    if(custom.size()==0) printf("0.0");
    else printf("%.1f",tottime/60.0/custom.size());
    return 0;
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Queueing theory is a mathematical study of waiting lines or queues that arise in various real-life scenarios, such as customer service, traffic congestion, hospital emergency rooms, and telecommunications networks. Basic queueing theory involves the following concepts: 1. Arrival Process: This is the process of customers arriving at the queue. The arrival process can be modeled using different distributions, such as Poisson or exponential. 2. Service Process: This is the process of serving customers in the queue. The service process can also be modeled using different distributions, such as Poisson or exponential. 3. Queue Length: This is the number of customers waiting in the queue at any given time. 4. Queue Occupancy: This is the proportion of time that the server is busy serving customers. 5. System Capacity: This is the maximum number of customers that the system can handle at any given time. 6. Utilization: This is the proportion of time that the server is busy serving customers compared to the total time. 7. Waiting Time: This is the time that a customer spends waiting in the queue before being served. 8. Service Time: This is the time that a customer spends being served by the server. 9. Queueing Models: There are different queueing models that can be used to analyze queueing systems, such as the M/M/1 model, M/M/c model, M/G/1 model, and M/D/1 model. 10. Performance Measures: Different performance measures can be used to evaluate queueing systems, such as average waiting time, average queue length, and system throughput.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值