PAT A1014 Waiting in Line (30 分)——队列
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.
- Customeri will take Ti 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 Specification:
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 Specification:
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
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <queue>
using namespace std;
const int maxn = ;
int n, m, k, q, now = ;
int t[maxn] = { };
int done[maxn] = { };
int pre[maxn] = { };
struct people {
int id;
int time;
int time_const;
};
queue<people*> que[];
int main() {
scanf("%d %d %d %d", &n, &m, &k, &q);
if (n == || m == ) {
for (int i = ; i < q; i++) {
printf("Sorry\n");
}
}
for (int i = ; i <= k; i++) {
int time;
scanf("%d", &time);
people *p = new people;
p->id = i;
p->time = time;
p->time_const = time;
if(i<=n*m)que[(i-)%n].push(p);
else {
int first = , first_j = ;
for (int j = ; j < n; j++) {
if (que[j].front()->time < first) {
first = que[j].front()->time;
first_j = j;
}
} for (int j = ; j < n; j++) {
que[j].front()->time -= first;
}
people* tmp_p = que[first_j].front();
que[first_j].pop();
now += first;
done[tmp_p->id] = now;
que[first_j].push(p);
pre[tmp_p->id] = now - tmp_p->time_const;
delete(tmp_p);
}
}
for (int i = ; i < n; i++) {
int tmp_now = now;
while (!que[i].empty()) {
people* tmp_p = que[i].front(); que[i].pop();
tmp_now += tmp_p->time;
pre[tmp_p->id] = tmp_now - tmp_p->time_const;
done[tmp_p->id] = tmp_now;
delete(tmp_p);
}
}
for (int i = ; i < q; i++) {
int j;
scanf("%d", &j);
//printf("%d %d\n", pre[j], done[j]);
if (pre[j]>=)printf("Sorry\n");
else {
printf("%02d:%02d\n", +done[j]/,done[j]%);
}
}
system("pause");
}
注意点:考察队列知识,相对比较简单,有一个坑就是结束时间在17点后但开始时间17点前还是要输出时间的,一开始没注意就错了三个测试点。
PAT A1014 Waiting in Line (30 分)——队列的更多相关文章
- PAT 1014 Waiting in Line (30分) 一个简单的思路
这题写了有一点时间,最开始想着优化一下时间,用优先队列去做,但是发现有锅,因为忽略了队的长度. 然后思考过后,觉得用时间线来模拟最好做,先把窗口前的队列填满,这样保证了队列的长度是统一的,这样的话如果 ...
- PAT 甲级 1014 Waiting in Line (30 分)(queue的使用,模拟题,有个大坑)
1014 Waiting in Line (30 分) Suppose a bank has N windows open for service. There is a yellow line ...
- 1014 Waiting in Line (30分)
1014 Waiting in Line (30分) Suppose a bank has N windows open for service. There is a yellow line i ...
- 【PAT甲级】1014 Waiting in Line (30 分)(队列维护)
题面: 输入四个正整数N,M,K,Q(N<=20,M<=10,K,Q<=1000),N为银行窗口数量,M为黄线内最大人数,K为需要服务的人数,Q为查询次数.输入K个正整数,分别代表每 ...
- PAT A 1014. Waiting in Line (30)【队列模拟】
题目:https://www.patest.cn/contests/pat-a-practise/1014 思路: 直接模拟类的题. 线内的各个窗口各为一个队,线外的为一个,按时间模拟出队.入队. 注 ...
- PAT-1014 Waiting in Line (30 分) 优先队列
Suppose a bank has N windows open for service. There is a yellow line in front of the windows which ...
- 1014 Waiting in Line (30 分)
Suppose a bank has N windows open for service. There is a yellow line in front of the windows which ...
- PTA 1014 Waiting in Line (30分) 解题思路及满分代码
题目 Suppose a bank has N windows open for service. There is a yellow line in front of the windows whi ...
- PAT 1014 Waiting in Line (模拟)
1014. Waiting in Line (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Suppo ...
随机推荐
- github-SSH模式如何配置秘钥clone远程仓库以及分支切换
一.ssh模式clone 恕我无知,之前使用git命令都是https模式,该模式每次push都需要输入账号和密码,而且速度会根据的网速的快慢而定. 近日电脑重装了系统,在用SSH模式clone远程仓库 ...
- 小程序webview应用实践
原文:小程序webview实践 作者:张所勇(转转开放业务部前端负责人) 公众号:大转转FE Fundebug经授权转载,版权归原作者所有. 大家好,我是转转开放业务部前端负责人张所勇,今天主要来跟大 ...
- 洛谷P3600 随机数生成器(期望dp 组合数)
题意 题目链接 Sol 一条重要的性质:如果某个区间覆盖了另一个区间,那么该区间是没有用的(不会对最大值做出贡献) 首先不难想到枚举最终的答案\(x\).这时我们需要计算的是最大值恰好为\(x\)的概 ...
- Python:随机生成测试数据的模块--faker的基本使用
本文内容: faker的介绍 faker的使用 小例子:生成随机的数据表信息 首发日期:2018-06-15 faker介绍: faker是python的一个第三方模块,是一个github上的开源项目 ...
- python之with语句的原理
首发时间:2018-02-23 15:28 之前看到一篇博客说博主python面试时遇到面试官提问with的原理,而那位博主的博文没有提及with原理,故有此文. 关于with语句,官方文档中是这样描 ...
- 为什么 APM 能提升 IT 团队工作质量?
“有必要吗?”这是很多 IT 专业人员在尝试向团队内部推荐应用程序性能管理价值时所面临的问题.APM(应用程序性能管理)能为公司节约成本,提高内部工作效率,并真实了解用户对公司的系统和产品是否满意.除 ...
- nginx 配置简单网站项目(linux下)
1.新建html2与html3两个网站项目测试,而html是本身就有,记得到/etc/hosts 添加dns记录 2.修改nginx.conf文件 3.测试访问 中间用到一些nginx的命令,就不截图 ...
- [20171220]toad plsql显示整形的bug.txt
[20171220]toad plsql显示整形的bug.txt --//下午有itpub网友反应,一个查询在sqlplus,pl/sql下不同.链接如下:--//http://www.itpub.n ...
- Azure 标准与高级托管磁盘存储的相互转换
托管磁盘提供两种存储选项:高级(基于 SSD)和标准(基于 HDD). 它允许基于性能需求在这两个选项之间轻松切换,并保障最短停机时间. 非托管磁盘不具备此功能. 但可以轻松转换为托管磁盘,以便在这两 ...
- oracle order by 排序
Syntax ORDER BY { column-Name | ColumnPosition | Expression } [ ASC | DESC ] [ NULLS FIRST | NULLS L ...