PAT1 1017 Queueing at Bank

题目链接
我的github

题目大意

银行有 K K K个窗口,如果有空闲的窗口,那么就允许顾客去这个空闲窗口处理业务,假设所有窗口最多只能被顾客占用1小时,现在给出所有顾客的到达银行的时间和每人处理业务的时间,现在需要计算出所有顾客的平均等待时间

输入

每组包含一个测试用例,每个用例的第一行包含两个数 N N N( ≤ 1 0 4 \leq 10^4 104, 顾客的数量), K K K( ≤ 100 \leq 100 100,窗口的数量),然后有 N N N行每行包含顾客到达银行的时间(HH:MM:SS)和处理业务的时间。HH的范围在[00, 23],MMSS的范围在[00, 59],假设同一时间不会有两个顾客到达银行,且银行的营业时间是08:00 ~ 17:00,任何早于08:00必须等到08:00,任何晚于17:00的顾客将不能被服务,且不会被计算进平均等待时间

输出

对每个例子以一行输出所有顾客的平均等待时间,精确到小数点后1位

样例输入

7 3
07:55:00 16
17:00:01 2
07:59:59 15
08:01:00 60
08:00:00 30
08:00:02 2
08:03:00 10

样例输出

8.2

解析

本题是个模拟题,先剔除晚于17:00的顾客,然后将剩下的顾客按照时间排序,再按照时间的流动模拟顾客的等待情况

import functools


class customer:
    def __init__(self, arr, pro):
        self.arr = arr  #顾客的到达时间
        self.pro = pro  #顾客的处理业务时间

    def toString(self):
        return "%d %d" % (self.arr, self.pro)


def cmp(a, b):  #自定义的比较函数
    if a.arr < b.arr:
        return -1
    if a.arr > b.arr:
        return 1
    return 0


def solve():
    n, k = map(int, input().split())
    customers = list()
    for i in range(n):
        time, pro = input().split()
        pro = int(pro)
        hour, minute, second = map(int, time.split(':'))
        arr = hour * 3600 + minute * 60 + second
        if arr > 61200: #晚于17:00就剔除
            continue
        customers.append(customer(arr, pro*60))
    customers.sort(key=functools.cmp_to_key(cmp))   #排序
    windows = [28800 for i in range(k)] #窗口开始的时间是8:00
    ans = 0.0
    for i in range(len(customers)):
        t = 0
        for j in range(k):  #找出最先空闲的窗口
            if windows[t] > windows[j]:
                t = j
        if windows[t] <= customers[i].arr:  #窗口在顾客来之前就空闲了
            windows[t] = customers[i].arr + customers[i].pro
        else:
            ans = ans + windows[t] - customers[i].arr
            windows[t] += customers[i].pro
    if len(customers) == 0: #如果没有可被服务的顾客输出0.0
        print("0.0")
    else:
        print("%.1f" % (ans / 60 / len(customers)))


if __name__ == "__main__":
    solve()

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

余额充值