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 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 (≤10?4??) - 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

代码:

#include <bits/stdc++.h>
using namespace std;

int N, M;

struct Node{
    int time;
    int wait;
};

vector<Node> v;

bool cmp(const Node &a, const Node &b) {
    return a.time < b.time;
}

int main() {
    scanf("%d%d", &N, &M);
    for(int i = 0; i < N; i ++) {
        Node n;
        int h, m, s, t;
        scanf("%d:%d:%d %d", &h, &m, &s, &t);
        n.time = h * 3600 + m * 60 + s;
        n.wait = t * 60;

        if(n.time <= 61200) v.push_back(n);
    }

    vector<int> win(M, 28800);
    //memset(win, 28800, sizeof(win));
    sort(v.begin(), v.end(), cmp);

    //for(int i = 0; i < v.size(); i ++)
        //printf("%d %d\n", v[i].time, v[i].wait);

    double total = 0.0;
    for(int i = 0; i < v.size(); i ++) {
        int temp = 0, minn = win[0];
        for(int j = 1; j < M; j ++) {
            if(win[j] < minn) {
                minn = win[j];
                temp = j;
            }
        }
        if(win[temp] <= v[i].time)
            win[temp] = v[i].time + v[i].wait;
        else {
            total += (win[temp] - v[i].time);
            win[temp] += v[i].wait;
        }
    }

        //cout << total;
    if(v.size() == 0) printf("0.0\n");
    else printf("%.1lf\n", total / 60.0 / v.size());
    return 0;
}

  把所有时间转换成秒 把来的人按照来的时间排序 在 17:00:00 之后的排除 更新最快结束的窗口

FH

原文地址:https://www.cnblogs.com/zlrrrr/p/10422167.html

时间: 2024-11-06 07:12:57

PAT 甲级 1017 Queueing at Bank的相关文章

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

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 tur

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) (坑题)

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) {} };

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

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

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

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

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