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 ...
随机推荐
- Java并发编程:线程池的使用(转载)
转载自:https://www.cnblogs.com/dolphin0520/p/3932921.html Java并发编程:线程池的使用 在前面的文章中,我们使用线程的时候就去创建一个线程,这样实 ...
- webpack4 系列教程(五): 处理CSS
这节课讲解webpack4中打包css的应用.v4 版本和 v3 版本并没有特别的出入. >>> 本节课源码 >>> 所有课程源码 教程所示图片使用的是 githu ...
- Java 内部类的简单介绍
内部类的三种分类(成员内部类,局部内部类,匿名内部类) 1.成员内部类 (类似于成员变量和成员方法) 在类的外部类的方法中去调用内部类 输出结果: 另一种直接在别的类中使用内部类,不过需要先创建外部 ...
- 纯CSS绘制mac代码
1.效果图 2.代码 <!doctype html> <html lang="en"> <head> <meta charset=&quo ...
- css实现照片上传的加号框
css实现照片上传的加号框
- ionic 开发解决ios上qq客服链接不跳转或者跳转到appstore
不能跳转的情况需要 在ionic项目根目录下,打开config.xml文件,在<access origin="*" />后添加<allow-navigation ...
- C# 插件式开发
在网上找了下插件式编程的资料,这里自己先借鉴下别人的,同时发现有自己的看法,不过由于本人水平有限,不一定有参考价值,写出来一方面是为了总结自己,以求提高,另一方面也希望各为朋友看到我的不足,给我提出宝 ...
- loadrunner 场景设计-手工场景方案(Schedule)设计
场景设计-手工场景方案(Schedule)设计 by:授客 QQ:1033553122 A. 定义方案schedule 在 Scenario Schedule面板中,选择一个方案schedule, ...
- Angular基础(三) TypeScript
一.模仿Reddit a) 运行ng new –ng4angular-reddit创建应用,从随书代码中复制样式文件,新建组件app-root,代码为: 界面可以看到了: b) 对于界面输入的数据,获 ...
- 基于VMware Workstation在Windows Server 2008 R2上搭建SQL Server 2012高可用性组(AlwaysOn Group)测试环境(二)
接上篇: 以SERVER02为例,将服务器加入域,并安装故障转移群集:(SERVER02-SERVER-04操作相同)