原题传送门

  • 队列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. 有源晶振和无源晶振的输出波形
  3. wall poj 1113
  4. 练习1-2:编写一个 JAVA 程序,实现输出考试成绩的前三名。
  5. 基于json-lib.jar包Json实例程序
  6. 《转》IN 查询时出现ORA-01795:列表中的最大表达式数为1000
  7. Veritas Backup Exec 21.3 Multilingual (Windows)
  8. npm下载以来版本问题 npm ERR! code ERESOLVE
  9. 【杂谈】网络修复杂谈
  10. win10有效清理c盘空间: 移动pagefile.sys和删除hiberfil.sys文件
  11. 携程网络防火墙自动化运维之道
  12. 大家保险发布“早下班一小时”倡议,呼吁“重阳节,不脱节”
  13. 利用jsoup解析网站网页
  14. 文昌京东配送小哥的那些骄傲事
  15. 分布式系统之道:Lamport 逻辑时钟
  16. 我的武林秘籍设计模式之命令模式
  17. BUGKU misc--细心的大象--writeup
  18. js面向对象编程基础
  19. Mysql之统计函数
  20. 麦芽糖醇(CAS 585-88-6)的全球与中国市场2022-2028年:技术、参与者、趋势、市场规模及占有率研究报告

热门文章

  1. thinkpad x61s 插 pcmia 安装 openwrt 启用双网卡
  2. Arduino与红外遥控握手
  3. MySQL 优化 —— IS NULL 优化
  4. cocos2d-x实现一个PopStar(消灭星星)游戏的逻辑分析及源码
  5. layui数据表格动态cols(字段)动态变化
  6. 微信小说项目如何防止域名屏蔽
  7. 【ArcGIS】道路中心线提取、河道中心线的提取
  8. w10计算机恢复出厂设置,如何给win10系统的电脑强制恢复出厂设置
  9. 转: Github上关于iOS的各种开源项目集合
  10. 实验报告怎么写之书写规范