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 customers 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 window1while 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
 #include<cstdio>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
using namespace std;
typedef struct{
queue<int> qu;
int nowT;
int endFirst;
}info;
info window[];
int N, M, K, Q;
int costum[], req[], leave[];
int main(){
scanf("%d%d%d%d", &N, &M, &K, &Q);
for(int i = ; i < K; i++){
scanf("%d", &costum[i]);
}
for(int i = ; i < Q; i++){
scanf("%d", &req[i]);
}
for(int i = ; i < N; i++){
window[i].nowT = * ;
}
for(int i = ; i < K; i++){
int index = -, minLine = ;
for(int j = ; j < N; j++){
if(window[j].qu.size() < minLine && window[j].qu.size() < M){
index = j;
minLine = window[j].qu.size();
}
}
if(index != -){
window[index].qu.push(i);
}else{
int popIndex = -, minTime = ;
for(int j = ; j < N; j++){
window[j].endFirst = window[j].nowT + costum[window[j].qu.front()];
if(window[j].endFirst < minTime){
popIndex = j;
minTime = window[j].endFirst;
}
}
window[popIndex].nowT = window[popIndex].endFirst;
leave[window[popIndex].qu.front()] = window[popIndex].endFirst;
window[popIndex].qu.pop();
window[popIndex].qu.push(i);
}
}
for(int i = ; i < N; i++){
while(window[i].qu.empty() == false){
int Ci = window[i].qu.front();
leave[Ci] = window[i].nowT + costum[Ci];
window[i].nowT = leave[Ci];
window[i].qu.pop();
}
}
for(int i = ; i < Q; i++){
req[i]--;
if(leave[req[i]] - costum[req[i]] >= * ){
printf("Sorry\n");
}else{
printf("%02d:%02d\n", leave[req[i]] / , leave[req[i]] % );
}
}
cin >> N;
return ;
}

总结:

1、题意:有N个窗口,每个窗口可以排队M个人,有K个顾客来办理。每次顾客都选择最短的队伍排队。

2、由于顾客优先选择队列人少的地方排队而不是提前结束服务的队伍排队,所以需要保留队列信息。当存在不满的队列时,找一个最短的队列,将顾客加入。当队列都满时,选择一个能最早服务完一个人的队列,则该队列就是最短的队列,服务完队首元素后将顾客加入。

3、题目中要求的是在5点后没有开始服务的人无法被服务,而非5点后没有完成业务的人无法被服务。

A1014. Waiting in Line的更多相关文章

  1. 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 ...

  2. PAT甲级——A1014 Waiting in Line

    Suppose a bank has N windows open for service. There is a yellow line in front of the windows which ...

  3. PAT Waiting in Line[转载]

    //转自:https://blog.csdn.net/apie_czx/article/details/45537627 1014 Waiting in Line (30)(30 分)Suppose ...

  4. PTA (Advanced Level) 1014 Waiting in Line

    Waiting in Line Suppose a bank has N windows open for service. There is a yellow line in front of th ...

  5. PAT甲级1014. Waiting in Line

    PAT甲级1014. Waiting in Line 题意: 假设银行有N个窗口可以开放服务.窗前有一条黄线,将等候区分为两部分.客户要排队的规则是: 每个窗口前面的黄线内的空间足以包含与M个客户的一 ...

  6. PAT 1014 Waiting in Line (模拟)

    1014. Waiting in Line (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Suppo ...

  7. pat1014. Waiting in Line (30)

    1014. Waiting in Line (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Suppo ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. CBV源码分析+APIVIew源码分析

    {drf,resful,apiview,序列化组件,视图组件,认证组件,权限组件,频率组件,解析器,分页器,响应器,URL控制器,版本控制} 一.CBV源码分析准备工作: 新建一个Django项目 写 ...

  2. mysql 中出现:不能打开到主机的连接,在端口3306: 连接失败

    由于某种原因,在服务器部署,然后mysql就连接不上了, navicat查看数据库正常,telnet怎么都不同,总会卡一会儿说遗失主机,最后终于找到解决办法 http://www.51testing. ...

  3. Python 命令行工具 argparse 模块使用详解

    先来介绍一把最基本的用法 import argparse parser = argparse.ArgumentParser() parser.parse_args() 在执行 parse_args() ...

  4. python读文件指定行的数据

    import linecacheprint linecache.getline('url.txt',2) 读取url.txt文件的第2行内容

  5. Math java

    package cn.liuliu.com; import java.math.BigDecimal; import java.math.BigInteger; /* * 一.Math类? * * 1 ...

  6. Hibernate 配置文件hibernate.cfg.xml的详细

    <!--标准的XML文件的起始行,version='1.0'表明XML的版本,encoding='gb2312'表明XML文件的编码方式-->               <?xml ...

  7. github上传时出现error: src refspec master does not match any解决办法22

    1 error:src refspec master does not match any这个问题,我之前也遇到过,这次又遇到了只是时间间隔比较长了,为了防止以后再遇到类似问题,还是把这个方法简单记录 ...

  8. struts2 的struts.xml配置文件

    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-/ ...

  9. windows 动态库的封装以及调用

    1.一个程序从源文件编译生成可执行文件的步骤:预编译 -->  编译 -->  汇编 --> 链接(1)预编译,即预处理,主要处理在源代码文件中以“#”开始的预编译指令,如宏展开.处 ...

  10. 51Nod1778 小Q的集合 【组合数】【Lucas定理】

    题目分析: 题解好高深...... 我给一个辣鸡做法算了,题解真的看不懂. 注意到方差恒为$0$,那么其实就是要我们求$\sum_{i=0}^{n}\binom{n}{i}(i^k-(n-i)^k)^ ...