• PAT A1017 Queueing at Bank


    1017 Queueing at Bank

    分数 25

    作者 CHEN, Yue

    单位 浙江大学

    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 (≤104) - 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:

    1. 7 3
    2. 07:55:00 16
    3. 17:00:01 2
    4. 07:59:59 15
    5. 08:01:00 60
    6. 08:00:00 30
    7. 08:00:02 2
    8. 08:03:00 10

    Sample Output:

    8.2

     

    敢情这个题是只要在17:00:00之前来到银行,就能够得到服务,不管在此之前已经
    有了多少人了。

    用优先队列存储每个窗口完成服务的时间(注意是完成),让时间越早完成,越先出队
    进行服务下一个顾客;

    1. /*
    2. 敢情这个题是只要在170000之前来到银行,就能够得到服务,不管在此之前已经
    3. 有了多少人了。
    4. 用优先队列存储每个窗口完成服务的时间(注意是完成),让时间越早完成,越先出队
    5. 进行服务下一个顾客;
    6. */
    7. #include <iostream>
    8. #include <algorithm>
    9. #include <queue>
    10. using namespace std;
    11. typedef long long LL;
    12. struct Infor
    13. {
    14. string come;
    15. int ser;
    16. bool operator < (const Infor &a) const
    17. {
    18. return come < a.come;
    19. }
    20. };
    21. const int N = 1e4+10;
    22. struct Infor a[N];
    23. int n, m;
    24. void Read()
    25. {
    26. cin >> n >> m;
    27. for(int i=0; i<n; ++i)
    28. {
    29. string come;
    30. int ser;
    31. cin >> come >> ser;
    32. if(ser > 60)
    33. ser = 60;
    34. ser *= 60;
    35. a[i] = {come, ser};
    36. }
    37. }
    38. int to_clock(string s)
    39. {
    40. int c = 0;
    41. int h = stoi(s.substr(0, 2));
    42. int m = stoi(s.substr(3, 2));
    43. int sec = stoi(s.substr(6, 2));
    44. c = h * 3600 + m * 60 + sec;
    45. return c;
    46. }
    47. double deal()
    48. {
    49. double sum = 0;
    50. int cnt = 0;
    51. priority_queue<LL, vector<LL>, greater<LL>> pq;
    52. sort(a, a+n);
    53. LL ope = to_clock("08:00:00"), cls = to_clock("17:00:00");
    54. //窗口服务开始,给每个窗口安排一个顾客
    55. for(int i=0; i<m && i<n; ++i)
    56. {
    57. LL t = to_clock(a[i].come);
    58. if(t > cls)
    59. break;
    60. if(t < ope)
    61. {
    62. sum += ope - t;
    63. pq.push(ope+a[i].ser);
    64. }
    65. else
    66. pq.push(t + a[i].ser);
    67. ++cnt;
    68. }
    69. //窗口先完成服务先出队
    70. for(int i=m; i<n; ++i)
    71. {
    72. LL u = pq.top();
    73. pq.pop();
    74. LL t = to_clock(a[i].come);
    75. if(t > cls)
    76. break;
    77. if(t >= u)
    78. pq.push(t + a[i].ser);
    79. else
    80. {
    81. sum += u - t;
    82. pq.push(u + a[i].ser);
    83. }
    84. ++cnt;
    85. }
    86. if(cnt == 0)
    87. return 0.0;
    88. return sum/ 60 / cnt;
    89. }
    90. int main()
    91. {
    92. Read();
    93. printf("%.1f\n",deal());
    94. return 0;
    95. }

  • 相关阅读:
    pycharm+selenium+edge环境配置
    Open3D 点云分割之区域生长
    面经-虚拟机-类加载
    C++程序设计-第六/七/八章 运算符重载/包含与继承/虚函数和多态性【期末复习|考研复习】
    部署和使用dinky问题总结
    【操作系统】esp栈指针
    分布式事务的锁
    网络协议:TCP三次握手与四次挥手
    Element & 8080端口被占用
    Vue中的异步组件
  • 原文地址:https://blog.csdn.net/qq_51825761/article/details/128045103