zoukankan      html  css  js  c++  java
  • PAT 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 (≤) - 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



     1 #include<iostream>
     2 #include<vector>
     3 #include<algorithm>
     4 #include<set>
     5 using namespace std;
     6 struct Node{
     7   int time, prc;
     8   Node(int a, int b){
     9     time = a;
    10     prc = b;
    11   }
    12 };
    13 bool cmp(Node a, Node b){ return a.time<b.time;}
    14 
    15 int main(){
    16   int n, k, i;
    17   scanf("%d%d", &n, &k);
    18   vector<Node> v;
    19   for(i=0; i<n; i++){
    20     int h, m, s, p;
    21     scanf("%d:%d:%d %d", &h, &m, &s, &p);
    22     v.push_back(Node(h*3600+m*60+s, p));
    23   }
    24   sort(v.begin(), v.end(), cmp);
    25   set<int> s;
    26   int sum=0, cnt=0;
    27   for(i=0; i<n; i++){
    28     if(v[i].time<8*3600){ //到达时间早于银行工作时间
    29       cnt++;
    30       if(s.size()<k){//排队等待人数少于窗口数
    31         s.insert(8*3600+v[i].prc*60);
    32             sum += (8*3600 - v[i].time);
    33       }else {//排队等待人数多于窗口数
    34         sum += (*(s.begin()) - v[i].time);
    35         s.insert(*(s.begin())+v[i].prc*60);
    36             s.erase(s.begin());
    37       }
    38     }else if(v[i].time<=17*3600){
    39       cnt++;
    40       if(s.size()<k) s.insert(v[i].time+v[i].prc*60);
    41       else{
    42             if(*(s.begin())>v[i].time){
    43               sum += (*(s.begin()) - v[i].time);
    44               s.insert(*(s.begin()) + v[i].prc*60);
    45               s.erase(s.begin());
    46             }else{
    47                 s.insert(v[i].time + v[i].prc*60);
    48                 s.erase(s.begin());
    49           }
    50       }
    51     }
    52   }
    53   printf("%.1f", sum*1.0/60/cnt);
    54   return 0;
    55 }
  • 相关阅读:
    【Centos7】卸载OpenJDK
    linux 网络测试命令 长期更新
    【Centos7】hostnamectl 设置主机名
    【VMware Workstation】虚拟机静态IP NAT连接外部网络(局域网以及广域网)
    【VMware Workstation】虚拟机动态IP NAT连接外部网络(局域网以及广域网)
    【刷题】BZOJ 4698 Sdoi2008 Sandy的卡片
    【刷题】BZOJ 1717 [Usaco2006 Dec]Milk Patterns 产奶的模式
    【刷题】洛谷 P3809 【模板】后缀排序
    【刷题】BZOJ 2038 [2009国家集训队]小Z的袜子(hose)
    【刷题】洛谷 P2709 小B的询问
  • 原文地址:https://www.cnblogs.com/mr-stn/p/9574208.html
Copyright © 2011-2022 走看看