PAT 甲级 1017 Queueing at Bank

PAT 甲级 1017 Queueing at Bank

n个人,k个窗口,要计算所有人的平均等待时长,我们让优先级队列记录每个人的结束时间,按最小堆排序,这样每次出队列的都是最早结束的。插入节点前判断一下,如果当前队首时间小于插入时间,说明该窗口空闲,插入即可。否则说明需要等待,记录等待时间q.top() - v[i].come

// 1017 Queueing at Bank.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#define maxN 10005
using namespace std;

struct person {
    int come, time;
};

bool cmp(person p1, person p2) {
    return p1.come < p2.come;
}
person v[maxN];
int main()
{
    int n, k,cnt = 0, total = 0;
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        int hour, second, minute, time;
        scanf("%d:%d:%d %d", &hour, &minute, &second, &time);
        int temp = hour * 60 * 60 + minute * 60 + second;
        if (temp > 61200) continue;
        v[++cnt].come = temp;
        v[cnt].time = time * 60;
    }
    sort(v + 1, v + 1 + cnt, cmp);
    priority_queue<int, vector<int>, greater<int> > q;
    for (int i = 1; i <= k; i++) q.push(28800);
    for (int i = 1; i <= cnt; i++) {
        if (q.top() <= v[i].come) {
            q.push(v[i].come + v[i].time);
            q.pop();
        }
        else {
            total += q.top() - v[i].come;
            q.push(q.top() + v[i].time);
            q.pop();
        }
    }
    (cnt == 0)? printf("0.0") :printf("%.1f", ((double)total / 60.0 / (double)cnt));
    return 0;
}

优先级队列 第一个参数为保存的数据类型,第二个参数为一个容器,一般为vector,不可为list

第三个参数默认为less< int> ,该优先级队列实现最大堆,队首的是数据最大的,降序排序

greater< int>代表最小堆,队首数据最小,升序排序

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、付费专栏及课程。

余额充值