题干:

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

题目大意:

假设银行有K个窗口为服务打开。窗户前面有一条黄线,把等候区分成两部分。所有的顾客都要在黄线后排队等候,直到轮到他/她时才有空位。假设没有一个客户可以占用一个窗口超过1小时。现在给定每个客户的到达时间T和处理时间P(单位是分钟),你应该告诉所有客户的平均等待时间。假设没有两个客户同时到达。注意,银行的营业时间是8点到17点。早到者必须排队等候至08:00,晚到者(17:00:01或17:00:01以后)不计算在内。

解题报告:

拿一个优先队列维护可用窗口就可以了,然后因为题意是按照到来的先后顺序排队等待的,所以不需要考虑(7:00:00 25)的顾客和(7:30:00 5)的顾客占用窗口的先后顺序问题,因为如果是按照最优方案的话肯定是先安排(7:30:00 5)的顾客更划算,因为他服务时间短,只有5分钟。复杂度是O(n*log(k)),如果不用优先队列的话复杂度是O(n*k),也可以AC。

甚至这题从8:00:00开始一秒一秒的模拟到18:00:00也可以,复杂度是O(36000*k)。可以思考一下为啥到18点而不是17点

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define FF first
#define SS second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e5 + 5;
int n,k;
priority_queue<int,vector<int>,greater<int> > pq;
struct Node {int t;int service;
} R[MAX];
int hh,mm,ss;
bool cmp(Node a,Node b) {return a.t < b.t;
}
const int ed = 17*3600;//17:00:00
const int st = 8 *3600;// 8:00:00
int main()
{cin>>n>>k;for(int i = 1; i<=n; i++) {scanf("%d:%d:%d%d",&hh,&mm,&ss,&R[i].service);R[i].service *= 60;R[i].t =  hh*3600 + mm*60 + ss;}sort(R+1,R+n+1,cmp);int wait = 0,all = 0;for(int i = 1; i<=n; i++) {if(R[i].t >= ed) break;all++;if(R[i].t < st) wait += st - R[i].t,R[i].t = st;if(pq.size() < k) pq.push(R[i].t + R[i].service);else {int cur = pq.top();pq.pop();if(cur < R[i].t) pq.push(R[i].t + R[i].service);else {wait += cur - R[i].t;pq.push(cur + R[i].service);}}}printf("%.1f\n",wait/60.0/all);return 0 ;
}

【PAT - 甲级1017】Queueing at Bank (25分)(优先队列,模拟)相关推荐

  1. PAT甲级1017 Queueing at Bank:[C++题解]字符串、结构体、最小堆

    文章目录 题目分析 题目链接 题目分析 客户数据用什么存呢? 好吧,还是用结构体. 结构体里面存什么呢? 到达时间 和服务时间. 窗口怎么存呢? 将窗口的开始服务时间从小到大存,自然想到小根堆. pr ...

  2. 1017 Queueing at Bank (25 分)_27行代码AC

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 Suppose a bank has K windows open for service. There is a yellow ...

  3. 1017 Queueing at Bank (25 分) 【未完成】【难度: 中 / 知识点: 模拟】

    https://pintia.cn/problem-sets/994805342720868352/problems/994805491530579968

  4. PAT甲级 1017 Queueing at Bank

    原题传送门 >>> 几个注意点: 1.凡是在17:00:00之前(包括17:00:00)到的顾客,银行都必须把它们完全服务完成.(也就是说,在这之前银行不下班). 这个设定也太迷惑了 ...

  5. 【PAT甲级 - 1028】List Sorting (25分)(模拟,排序)

    题干: Excel can sort records according to any column. Now you are supposed to imitate this function. I ...

  6. PAT甲级1009 Product of Polynomials (25分)

    PAT甲级1009 Product of Polynomials (25分) 题目: 题目分析:和之前有一道多项式相加很像,注意点是不仅仅数组系数会变,还可能会出现之前没有的指数,因此要开2001大小 ...

  7. 17冬第二题 PAT甲级 1141 Ranking of Institutions (25分) 有点鸡贼

    题目 After each PAT, the PAT Center will announce the ranking of institutions based on their students' ...

  8. PAT甲级 -- 1009 Product of Polynomials (25 分)

    This time, you are supposed to find A×B where A and B are two polynomials. Input Specification: Each ...

  9. PAT甲级-1021 Deepest Root(25分)

    题目:1021 Deepest Root(25分) 分析:找出以某个节点为根时,最深的根,这题可能会超时要用vector来表示二维数组 疑问:代码一是第二次写的超时了,代码二是第一次写的AC了,找不出 ...

  10. PAT甲级--1007 Maximum Subsequence Sum (25 分)

    题目详情 - 1007 Maximum Subsequence Sum (25 分) (pintia.cn) Given a sequence of K integers { N1​, N2​, .. ...

最新文章

  1. centos 5.3 配置sendmail服务器
  2. dojo自定义表格组件
  3. 桑文锋PMCAFF之行:数据驱动产品和运营决策
  4. linux平台下rpm方式和源码包方式安装mysql5.7
  5. BOOST_VMD_ASSERT宏相关的测试程序
  6. Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4) 构造
  7. java 引用被回收_java GC 静态List 如果没有引用会被回收吗
  8. C#中List与IList的区别
  9. 怎么下载计算机考试准考证
  10. 怎么把matlab的背景改成白色背景图片,如何把图片背景换成白色?
  11. ListView源码(推荐)
  12. 高通耳机阻抗估算流程
  13. 理解深度神经网络——DNN(Deep Neural Networks)
  14. Rational Rose7.0的安装(含图详解)
  15. matlab cell 颜色,MATLAB 的 cell 大法(单元格数组)
  16. 亚马逊APP更换新图标,尴尬又不失礼貌的“微笑”
  17. 树莓派 --- 基于OpenCV实现人脸识别
  18. 全国中小学信息技术创新与实践大赛:加码未来编程赛道
  19. 计算机二级2016知识题库,2016年计算机二级考试题库(带答案)
  20. 求解最大流的四种算法介绍、利用最大流模型解题入门

热门文章

  1. 人这辈子没法做太多的事情
  2. SmartFox中的類型轉換
  3. 第六课 从词向量到NLP分类问题
  4. 【Breadth-first Search 】103. Binary Tree Zigzag Level Order Traversal
  5. [Leetcode][第5458题][JAVA][字符串的好分割数目][双指针][HashSet]
  6. [剑指offer]面试题第[35]题[Leetcode][第138题][JAVA][复杂链表的复制][暴力][HashMap][复制链表]
  7. 树状数组的区间修改+查询
  8. 不同型号服务器如何做双击热备,服务器做双机热备教程
  9. 登录微信用android设备,Android 之微信登录
  10. php 自带缓存,封装ThinkPhP自带的缓存机制