• 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/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 (≤) - the total number of customers, and K (≤) - 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

    又来一记模拟题,优先队列加个友元函数排序,然后注意边界条件8:00~17:00

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 int start_time = 28800;
     4 int end_time = 61201;
     5 int n, k;
     6 char c;
     7 struct Node{
     8     int ari_time;
     9     int wait;
    10     friend bool operator<(const Node &a, const Node &b){
    11         return a.ari_time > b.ari_time;
    12     }
    13 }node[10010];
    14 double sum = 0;
    15 int pos = 0;
    16 priority_queue<Node> q1, q2;//q1放窗口,q2放排队
    17 
    18 int main(){
    19     cin >> n >> k;
    20     int h, m, s;
    21     for(int i = 0; i < n; i++){
    22         cin >>h>>c>>m>>c>>s>>node[i].wait;
    23         node[i].ari_time = h*60*60+m*60+s;
    24         node[i].wait *= 60;
    25     }
    26     for(int i = 0; i < n; i++){
    27         if(node[i].ari_time < end_time){
    28             q2.push(node[i]);
    29         }
    30     }
    31     while(q1.size()<k && !q2.empty()){
    32         Node ans = q2.top();
    33         q2.pop();
    34         if(!q1.empty()){
    35             Node cnt = q1.top();
    36             if(cnt.ari_time <= ans.ari_time)
    37                 q1.pop();
    38         }
    39         if(ans.ari_time < start_time){
    40             sum += start_time - ans.ari_time;
    41         }
    42         ans.ari_time = ans.wait + max(ans.ari_time,start_time);
    43         q1.push(ans);
    44         pos++;
    45     }
    46     while(!q2.empty()){
    47         Node ans = q2.top();
    48         q2.pop();
    49         Node cnt = q1.top();
    50         q1.pop();
    51         if(cnt.ari_time > ans.ari_time){
    52             sum += cnt.ari_time - ans.ari_time;
    53         }
    54         ans.ari_time = max(cnt.ari_time, ans.ari_time) + ans.wait;
    55         q1.push(ans);
    56         pos++;
    57     }
    58     sum = sum/(double)(pos)/60.0;
    59     printf("%0.1lf
    ", sum);
    60     return 0;
    61 }
     
  • 相关阅读:
    火狐下button标签子元素无法点击
    js里面的this指向
    (转载)http协议的Request Payload 和 Form Data 的区别
    (转载)http压缩 Content-Encoding: gzip
    函数的length属性
    Expires
    Etag 和 If-None-Match
    Mac下升级node到最新版本
    高级函数之函数绑定
    Java数据结构和算法day01 稀疏数组与队列
  • 原文地址:https://www.cnblogs.com/zllwxm123/p/11012611.html
Copyright © 2020-2023  润新知