PAT-甲级-1017. Queueing at Bank【模拟】


1017. Queueing at Bank



Suppose a bank has K windows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. All the customers have to wait in line behind the yellow line, until it is his/her turn to be served and there is a window available. It is assumed that no window can be occupied by a single customer for more than 1 hour.

Now given the arriving time T and the processing time P of each customer, you are supposed to tell the average waiting time of all the customers.

Input Specification:

Each input file contains one test case. For each case, the first line contains 2 numbers: N (<=10000) - the total number of customers, and K (<=100) - the number of windows. Then N lines follow, each contains 2 times: HH:MM:SS - the arriving time, and P - the processing time in minutes of a customer. Here HH is in the range [00, 23], MM and SS are both in [00, 59]. It is assumed that no two customers arrives at the same time.

Notice that the bank opens from 08:00 to 17:00. Anyone arrives early will have to wait in line till 08:00, and anyone comes too late (at or after 17:00:01) will not be served nor counted into the average.

Output Specification:

For each test case, print in one line the average waiting time of all the customers, in minutes and accurate up to 1 decimal place.

Sample Input:

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

Sample Output:

8.2

题目链接:PAT-1017

题目大意:给出n个人,k个窗口。接下来输入每个人到达时间以及办业务的时间。问平均每个人的等待时间是多少,以分钟计算

题目思路:处理业务从[8:00,17:00]。早于8:00需要等待到8:00开始处理,到达时间晚于17:00则不处理。如果17:00之前到达但是处理到17:00之后,是允许的。

另外,计算平均等待时间,晚于17:00的人是不计算进去的!!(因为这个调好久)

其他直接模拟就可以了

以下是代码:

#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue>
#include<iomanip>
using namespace std;
int t[105];
struct node
{
    int time,need;
}p[10005];
bool cmp(node a,node b)
{
    return a.time < b.time;
}
int main()
{
    int n,k;
    cin >> n >> k;
    int h,m,s,ans = 0;
    int begin = 8 * 60 * 60;
    int end = 17 * 60 * 60;
    for (int i = 0; i < k; i++)
    {
        t[i] = begin;
    }
    for (int i = 0; i < n; i++)
    {
        scanf("%d:%d:%d %d",&h,&m,&s,&p[i].need);
        p[i].time = (h * 60 + m) * 60 + s;
        p[i].need *= 60;
    }
    sort(p, p + n,cmp);
    int cnt = 0;
    for (int i = 0; i < n; i++)
    {
        if (p[i].time > end) continue;
        int poi = 0;
        for (int j = 0; j < k; j++)
        {
            if (t[j] < t[poi])  poi = j;
        }
        if (t[poi] >= p[i].time)
        {
            ans += t[poi] - p[i].time;
            t[poi] += p[i].need;
        }
        else  t[poi] = p[i].time + p[i].need;
        cnt++;  //记录处理业务的人数
    }
    printf("%.1f\n",(ans * 1.0 / (60 * cnt)));
    return 0;
}
时间: 2024-08-08 10:34:26

PAT-甲级-1017. Queueing at Bank【模拟】的相关文章

PAT 甲级 1017 Queueing at Bank

https://pintia.cn/problem-sets/994805342720868352/problems/994805491530579968 Suppose a bank has K windows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. All the customers have to wait

PAT 1017 Queueing at Bank[一般]

1017 Queueing at Bank (25)(25 分)提问 Suppose a bank has K windows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. All the customers have to wait in line behind the yellow line, until it is

1017 Queueing at Bank (25 分)

1017 Queueing at Bank (25 分) Suppose a bank has K windows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. All the customers have to wait in line behind the yellow line, until it is his/h

PAT甲题题解-1017. Queueing at Bank (25)-模拟

有n个客户和k个窗口,给出n个客户的到达时间和需要的时长有空闲的窗口就去办理,没有的话就需要等待,求客户的平均时长.如果在8点前来的,就需要等到8点.如果17点以后来的,则不会被服务,无需考虑. 按客户的到达时间排序建立一个优先级队列,一开始放入k个窗口,初始结束时间为8*3600然后for循环客户,每次从优先级队列中取出最早结束时间的窗口如果客户比结束时间来的早,就需要等待如果客户比结束时间来的晚,就无需等待最后只要统计那些到达时间在17*3600之前的客户即可. #include <iost

PAT 1017 Queueing at Bank (25) (坑题)

Suppose a bank has K windows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. All the customers have to wait in line behind the yellow line, until it is his/her turn to be served and ther

PAT 1017. Queueing at Bank

又是排队模拟 #include <iostream> #include <cstdlib> #include <vector> #include <list> #include <queue> using namespace std; class Man { public: int arrive; int need; int start; Man(int a, int n) : arrive(a), need(n), start(0) {} };

1017 Queueing at Bank (我自己写的模拟时间的版本)

Suppose a bank has K windows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. All the customers have to wait in line behind the yellow line, until it is his/her turn to be served and ther

1017. Queueing at Bank (25) - priority_queuet

题目如下: Suppose a bank has K windows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. All the customers have to wait in line behind the yellow line, until it is his/her turn to be served an

PAT甲级1026 Table Tennis【模拟好题】

题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805472333250560 题意: 有k张乒乓球桌,有的是vip桌.有n对玩家来打乒乓,有的玩家是VIP玩家. 当他们到达时,如果没有空桌子他们就排队等待. 这时候如果有VIP桌子空出来了,那么就优先给队列里的VIP玩家,如果没有VIP玩家就给普通玩家. 如果普通桌子空出来了,就给队列里排在最前的玩家. 如果玩家到达的时候有好多桌子可以选择,那么他会选择桌号最小的