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. 简单JQuery+AJAX+Servlet的计算器实现

    index.jsp <%@ page language="java" contentType="text/html; charset=UTF-8" pag ...

  2. Fiddler 学习笔记---命令、断点

    输入命令框: 1 输入 ?51testing  高亮显示对应记录 2 >10 选择body大于10的记录 3 <10 选择body<10的记录 4 =200 选择result=200 ...

  3. falsk 项目中日志设置

    app/__init__.py: 1 import logging from logging.handlers import RotatingFileHandler ''' 开发中使用DEBUG级别, ...

  4. css元素选择器

    css的元素选择器就是html的标签名:

  5. Java多线程之定时任务(Timer)

    package org.study2.javabase.ThreadsDemo.schedule; import java.util.Date; import java.util.Timer; imp ...

  6. Mvc校验用户没有登录就跳转的实现

    看字面意思很简单,就是判断用户是否登录了,如果没有登录就跳转到登陆页面. 没错,主要代码如下(这里就不写判断登录了,直接跳转) 首先在控制器中新建一个BaseController public cla ...

  7. DEV GridControl/TreeList 中ShowingEditor使用

    ShowingEditor事件对我来说就是控制单元格的编辑属性,在特定场景中(TreeList中要求子节点某些列可编辑,父节点不可编辑)就需要使用此事件来实现,与此同时,上一篇也介绍了特定场景单元格样 ...

  8. servlet篇 之 生命周期

    二:Servlet的生命周期 背景知识: servlet是单例,在web项目运行期间,一个servlet只会创建一个对象[tomcat帮我们实例 化][尽量不要在servlet中定义成员变量].因为w ...

  9. fastjson的JSONArray和JSONObject

    转自: http://blog.csdn.net/tangerr/article/details/76217924 Fastjson是国内著名的电子商务互联网公司阿里巴巴内部开发的用于java后台处理 ...

  10. Python中第三方模块requests解析

    一.简述 Requests HTTP Library 二.模块框架 ''' __version__ _internal_utils adapters api auth certs compat coo ...