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 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 (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 (≤, number of windows), M (≤, the maximum capacity of each line inside the yellow line), K (≤, number of customers), and Q (≤, 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
注意 对于服务结束时间超出17点 但是开始时间小于17点的 也可以服务完成
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
struct T
{
int Hour=;
int Minute=;
}T1[],T2[];
int Time[];
int Tag = ;
int main()
{
int N, M, K, Q;
cin >> N >> M >> K >> Q;
queue<int> Queue[];
for (int i = ; i <=K; i++)
cin >> Time[i];
for(int j=;j<M;j++)
for (int i = ; i < N; i++)
{
if(Tag<=K)
Queue[i].push(Tag++);
}
for (int j = ; j < K; j++)
{
int Min = ;
int Minp = -;
for (int i = ; i < N; i++)
{
if(!Queue[i].empty())
if ((T1[i].Hour * + T1[i].Minute + Time[Queue[i].front()]) < Min)
{
Min = T1[i].Hour * + T1[i].Minute + Time[Queue[i].front()];
Minp = i;
}
}
int num =Queue[Minp].front();
T1[Minp].Hour += (T1[Minp].Minute + Time[num]) / ;
T1[Minp].Minute = (T1[Minp].Minute + Time[num]) % ;
T2[num].Hour = T1[Minp].Hour;
T2[num].Minute = T1[Minp].Minute;
Queue[Minp].pop();
if (Tag <= K)
Queue[Minp].push(Tag++);
}
int q;
for (int i = ; i < Q; i++)
{
cin >> q;
if (T2[q].Hour < || (T2[q].Hour == && T2[q].Minute - Time[q] < ))
printf("%02d:%02d\n", T2[q].Hour, T2[q].Minute);
else
cout << "Sorry" << endl;
}
return ;
}
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 ...
- 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 (30分) 一个简单的思路
这题写了有一点时间,最开始想着优化一下时间,用优先队列去做,但是发现有锅,因为忽略了队的长度. 然后思考过后,觉得用时间线来模拟最好做,先把窗口前的队列填满,这样保证了队列的长度是统一的,这样的话如果 ...
- 【PAT甲级】1014 Waiting in Line (30 分)(队列维护)
题面: 输入四个正整数N,M,K,Q(N<=20,M<=10,K,Q<=1000),N为银行窗口数量,M为黄线内最大人数,K为需要服务的人数,Q为查询次数.输入K个正整数,分别代表每 ...
- 1014 Waiting in Line (30)(30 分)
Suppose a bank has N windows open for service. There is a yellow line in front of the windows which ...
- PAT A 1014. Waiting in Line (30)【队列模拟】
题目:https://www.patest.cn/contests/pat-a-practise/1014 思路: 直接模拟类的题. 线内的各个窗口各为一个队,线外的为一个,按时间模拟出队.入队. 注 ...
- 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)(30 point(s))
problem Suppose a bank has N windows open for service. There is a yellow line in front of the window ...
随机推荐
- 【01】openLayers 第一个地图
效果: 代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <t ...
- django 从零开始 2迁移模型数据到数据库中和admin初识
和flask 一样 如果模型models 发生改动,则需要进行一个迁移数据库,但是我还没有想讲到那么深入,现在模型是django自带的一些sessiong,damin之类的模型 所以如果你想进去adm ...
- Linux 文件系统及 ext2 文件系统
linux 支持的文件系统类型 Ext2: 有点像 UNIX 文件系统.有 blocks,inodes,directories 的概念. Ext3: Ext2 的加强版,添加了日志 ...
- js String方法总结
字符方法(3) charAt(pos: number): string; // 返回特定位置的字符. charCodeAt(index: number): number; // 返回表示给定索引的字符 ...
- Hacker101-CTF | Postbook
Hacker101-CTF | Postbook mirror王宇阳 水平有限,不足之处还望指教 ^_^ 看看这个一大堆英文介绍 With this amazing tool you can writ ...
- Java 并发同步工具(转)
转自:https://www.jianshu.com/p/e80043ac4115 在 java 1.5 中,提供了一些非常有用的辅助类来帮助我们进行并发编程,比如 CountDownLatch,Cy ...
- Ruby中的Hash(哈希),你可以理解为字典
原文链接 以下代码在Ruby 2.5.1中编译通过 定义 myHash = Hash.new myHash1 = Hash["key1" => 100, "key2 ...
- jsp(3,6,9) EL表达式及JSTL
1. jsp 1.1jsp是什么 全称: Java Server Pages,java服务器页面.和Servlet一样,是sun公司定义的一种动态网页开发技术. 特点:基于html模版,可以在h ...
- selenium3浏览器驱动设置
设置浏览器驱动: 1.首先手动创建一个存放浏览器驱动的目录,如: C:\driver , 将下载的浏览器驱动文件(例如:chromedriver.geckodriver)丢到该目录下. 2.打开计算机 ...
- P5021 赛道修建 题解
原题链接 简要题意: 在一棵树上求 \(m\) 条不相交的路径的最小值的最大值. 本题部分分很多,而且本人也交了 \(27\) 次,所以一定要仔细讲部分分! 算法一 对于 \(b_i = a_i + ...