原题传送门

  • 队列queue的应用
  • 判断是否出队的方法:模拟时间流动,依次检查各个窗口队列
  • 时间的处理:先用十进制,最后输出时间格式
#include<iostream>
#include<queue>
using namespace std;const int MAXN = 22;
const int MAXK = 1000 + 5;
int N, M, K, Q; // 窗口数、黄线内容量、顾客数量、查询数量
int now_time = 0;
int close_time = (17 - 8) * 60;struct customer {int id;int process_time;   // 服务所需时间int done_time;  // 服务完成时间customer():done_time(-1) {}  // done_time=-1没有更新时输出sorry
} customers[MAXK];queue<customer> line[MAXN], behindQueue;    // 每个窗口对应一个黄线内队列line,黄线外是一个排队队列
int last_time[MAXN] = { 0 };    // 记录每个窗口队列的前一次的完成时间,即队头的开始时间int main() {cin >> N >> M >> K >> Q;int capacity = N * M;for (int i = 1; i <= K; i++) {cin >> customers[i].process_time;customers[i].id = i;if (i <= capacity) {line[(i - 1) % N + 1].push(customers[i]);} else {behindQueue.push(customers[i]); // 黄线外排队}}int count = K;while (now_time<close_time && count) {   // 模拟时间流动,每分钟检查一次有没有完成的now_time++;for (int i = 1; i <= N; i++) {  // 依次对各窗口的队头进行检查if (!line[i].empty()) {int done_time = line[i].front().process_time + last_time[i];    // 队头客户的完成时间int id = line[i].front().id;    // 队头客户的idif (last_time[i]<now_time && (done_time>close_time || done_time==now_time)) {   // 这样理解:在前一个人完成时间小于现在时间的情况下(即在17点前开始服务),队头超时完成服务或者现在完成了服务,这时候正式更新done_timecustomers[id].done_time = done_time;last_time[i] = done_time;line[i].pop();count--;if (behindQueue.size()) {line[i].push(behindQueue.front());behindQueue.pop();}} else if (last_time[i] >= now_time) {  // 17点前还没开始服务的,黄线内客户直接跳过,不更新done_time)line[i].pop();count--;if (behindQueue.size()) {line[i].push(behindQueue.front());behindQueue.pop();}}}}}int query;for (int i = 0; i < Q; i++) {   // 输出各个有效的done_timecin >> query;if (customers[query].done_time != -1)printf("%02d:%02d\n", 8 + customers[query].done_time / 60, customers[query].done_time % 60);elseprintf("Sorry\n");}return 0;
}

附原题:

Suppose a bank has N windows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. The rules for the customers to wait in line are:

The space inside the yellow line in front of each window is enough to contain a line with M customers. Hence when all the N lines are full, all the customers after (and including) the (NM+1)st one will have to wait in a line behind the yellow line.
Each customer will choose the shortest line to wait in when crossing the yellow line. If there are two or more lines with the same length, the customer will always choose the window with the smallest number.
Customer[i] will take T[i] minutes to have his/her transaction processed.
The first N customers are assumed to be served at 8:00am.
Now given the processing time of each customer, you are supposed to tell the exact time at which a customer has his/her business done.

For example, suppose that a bank has 2 windows and each window may have 2 custmers waiting inside the yellow line. There are 5 customers waiting with transactions taking 1, 2, 6, 4 and 3 minutes, respectively. At 08:00 in the morning, customer1 is served at window1 while customer2 is served at window2. Customer3 will wait in front of window1 and customer4 will wait in front of window2. Customer5 will wait behind the yellow line.

At 08:01, customer1 is done and customer5 enters the line in front of window1 since that line seems shorter now. Customer2 will leave at 08:02, customer4 at 08:06, customer3 at 08:07, and finally customer5 at 08:10.

  • Input

Each input file contains one test case. Each case starts with a line containing 4 positive integers: N (<=20, number of windows), M (<=10, the maximum capacity of each line inside the yellow line), K (<=1000, number of customers), and Q (<=1000, number of customer queries).

The next line contains K positive integers, which are the processing time of the K customers.

The last line contains Q positive integers, which represent the customers who are asking about the time they can have their transactions done. The customers are numbered from 1 to K.

  • Output

For each of the Q customers, print in one line the time at which his/her transaction is finished, in the format HH:MM where HH is in [08, 17] and MM is in [00, 59]. Note that since the bank is closed everyday after 17:00, for those customers who cannot be served before 17:00, you must output “Sorry” instead.

  • Sample Input
    2 2 7 5
    1 2 6 4 3 534 2
    3 4 5 6 7
  • Sample Output
    08:07
    08:06
    08:10
    17:00
    Sorry

PAT 甲级 1014. Waiting in Line相关推荐

  1. PAT甲级 1014 刷题记录

    文章目录 一.答案 (一)推荐答案 (二)个人解答 二.坑点 三.相关知识 (一)vector 与queue 两种结构的使用方法 (二)其他 一.答案 (一)推荐答案 链接:PAT甲级1014 测试点 ...

  2. 1014 Waiting in Line 队列操作

    目录 题目 输入样例 输出样例 提交结果截图 带详细注释的源代码 题目 题目链接:1014 Waiting in Line (PAT (Advanced Level) Practice) 输入样例 2 ...

  3. 【一遍过!!!】1014 Waiting in Line (30 分)(题意+分析)

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

  4. PAT 1014 Waiting in Line

    2019独角兽企业重金招聘Python工程师标准>>> 1: 全错, 修改下句增加queryCnt<q 的判断: while(queryCnt < q && ...

  5. PAT (Advanced Level) 1014. Waiting in Line (30)

    简单模拟题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm& ...

  6. PAT (Advanced Level) 1014 Waiting in Line(模拟)

    题目链接:点击查看 题目大意:给出规则,要求模拟客户到银行办理手续的过程:为了方便描述,下面将分为等待区和服务区来称呼 银行共有n个窗口,每个窗口最多可以有m个人排队,这里我们称为服务区 若窗口排队人 ...

  7. 1014 Waiting in Line (30 分) 【未完成】【难度: 难 / 知识点: 大模拟】

    https://pintia.cn/problem-sets/994805342720868352/problems/994805498207911936 大模拟代码有时间补

  8. pat甲级1014柳神代码解析自学复盘用

    这道题我自己是很没头绪,感觉这种题没什么算法但却很难. 这里有点抽象类的感觉, 1,首先,对于输入的每个人的办事时间,开辟了time[]数组来存储每个人的时间,实际上每个人也只有他的时间信息和下标信息 ...

  9. PAT甲级训练合集(1-70)

    本章题解跳转 考点 P1001 数字的数组表示和处理 P1002 多项式的数组表示和处理 P1003 深度优先搜素 P1004 深度优先搜素 P1005 哈希表 P1006 P1007 数组子区间求和 ...

  10. 【PAT】PAT甲级题库所有题解(持续更新中...)

    题解: 本文为导航页,一些希望刷PAT甲级的玩家可以来看看,我会持续更新所有题目的题解(取决于我做到哪儿了(doge)) 题号按照PAT官网给出的标注 题目: 链接 标签 1001 A+B Forma ...

最新文章

  1. 【组合数学】排列组合 ( 排列组合示例 )
  2. Cf Round #403 B. The Meeting Place Cannot Be Changed(二分答案)
  3. 曾经成功的敏捷团队为什么失败?
  4. 《javaScript100例|01》超级经典一套鼠标控制左右滚动图片带自动翻滚
  5. 【Leetcode | 顺序刷题 】二分查找目录
  6. asp python 定时任务_Ubuntu使用crontab定时执行python脚本
  7. SC-RoadDeepNet学习笔记
  8. 基于Web的在线教师备课系统
  9. 湖北武汉劳务员证书劳务人员实名制管理的策略建筑七大员培训
  10. AccessController的doPrivileged使用
  11. 捋一捋二分类和多分类中的交叉熵损失函数
  12. linux中524端口,liunx下攻击分析及如何通过交换机封端口
  13. Windows Server 2012修改光驱盘符
  14. outlook电子邮件解析_放大Outlook 2007中的电子邮件
  15. oracle sql语句加速选项,Oracle SQL优化基本步骤
  16. 计算机网络超时重传时间,TCP超时重传机制
  17. [转]傻博士评论《失业大军中的CCIE们》和现实社会!
  18. seo排名系统源码,矩阵系统源码,火剪系统源码
  19. 问题随记 —— Git 多账号配置问题
  20. linux如何查看丢弃数据包,导致Linux服务器丢弃数据包?

热门文章

  1. java繁体_Java-汉字繁体拼音转换
  2. 华为云服务查找手机_华为云服务登录入口
  3. Cesium加载面状geojson数据,并拉伸一定的高度。
  4. thinkpad10平板电脑装linux,ThinkPad X61上经历Ubuntu 8.10(安装笔记)
  5. win10 NET Framework 3.5(包括.NET 2.0和3.0)错误代码0x800f081f 的解决方法
  6. python substract_Python layers.Subtract方法代码示例
  7. TLC5615 产生频率可变的正弦波
  8. 基于FPGA驱动TLC5615模块
  9. 伪装文件病毒分析-流氓软件
  10. k-nearest neighbors algorithm - k 最近邻算法