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

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
// 1014pat2.cpp : 定义控制台应用程序的入口点。
// #include <fstream>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <memory.h>
#include <iomanip>
using namespace std;
const int N=;
const int INF=0x7fffffff; struct Custome
{
int id;
int time;
}; void query(int time,int& hh,int& mm)
{
hh=time/;
hh+=;
mm=time%;
} int main()
{
while(cinf>>n>>m>>k>>q)
{
vector<int> custime;
custime.push_back();
int tmp;
for(int i=;i<=k;++i)
{
cinf>>tmp;
custime.push_back(tmp);
}
queue<int> qq;
for(int i=;i<=q;++i)
{
cinf>>tmp;
qq.push(tmp);
}
vector<Custome> Windows[N];
Custome ctmp;
for(int i=;i<=m;++i)
{
for(int j=;j<=n;++j)
{
tmp=n*(i-)+j;
ctmp.id=tmp;
ctmp.time=custime[tmp];
Windows[j].push_back(ctmp);
}
}
int cntTime[N];
memset(cntTime,,sizeof(cntTime));
int min;
int window;
int id;
map<int,int> cmap;
for(int i=n*m+;i<=k;++i)
{
min=INF;
window=;
id=;
for(int j=;j<=n;++j)
{
if(Windows[j][].time<min)
{
min=Windows[j][].time;
window=j;
id=Windows[j][].id;
}
}
for(int i=;i<=n;++i)
{
Windows[i][].time-=min;
cntTime[i]+=min;
}
Windows[window].erase(Windows[window].begin());
ctmp.id=i;
ctmp.time=custime[i];
Windows[window].push_back(ctmp);
cmap[id]=cntTime[window];
}
for(int i=;i<=n;++i)
{
for(int j=;j<m;++j)
{
cntTime[i]+=Windows[i][j].time;
cmap[Windows[i][j].id]=cntTime[i];
}
}
int hh,mm;
while(!qq.empty())
{
tmp=qq.front();
qq.pop();
if(cmap[tmp]!=)
{
query(cmap[tmp]-custime[tmp],hh,mm);
if(hh>||hh==&&mm>=)
cout<<"Sorry"<<endl;
else
{
query(cmap[tmp],hh,mm);
cout<<setfill('')<<setw()<<hh<<":"<<setfill('')<<setw()<<mm<<endl;
}
}
}
}
return ;
}

PAT 1014. Waiting in Line的更多相关文章

  1. PAT 1014 Waiting in Line (模拟)

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

  2. PAT 1014 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 1014 Waiting in Line (30分) 一个简单的思路

    这题写了有一点时间,最开始想着优化一下时间,用优先队列去做,但是发现有锅,因为忽略了队的长度. 然后思考过后,觉得用时间线来模拟最好做,先把窗口前的队列填满,这样保证了队列的长度是统一的,这样的话如果 ...

  4. PAT甲级1014. Waiting in Line

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

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

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

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

  8. PAT A 1014. Waiting in Line (30)【队列模拟】

    题目:https://www.patest.cn/contests/pat-a-practise/1014 思路: 直接模拟类的题. 线内的各个窗口各为一个队,线外的为一个,按时间模拟出队.入队. 注 ...

  9. PAT甲题题解-1014. Waiting in Line (30)-模拟,优先级队列

    题意:n个窗口,每个窗口可以排m人.有k为顾客需要办理业务,给出了每个客户的办理业务时间.银行在8点开始服务,如果窗口都排满了,客户就得在黄线外等候.如果有一个窗口用户服务结束,黄线外的客户就进来一个 ...

随机推荐

  1. 启动Tomcat出现Using CATALINA_BASE

    有一次命令行启动Tomcat的时候,出现: Using CATALINA_BASE: "D:\apache-tomcat-6.0.35"Using CATALINA_HOME: & ...

  2. html 5 中的 6位 十六进制颜色码 代表的意思

    人的眼睛看到的颜色有两种: ⒈ 一种是发光体发出的颜色,比如计算机显示器屏幕显示的颜色: ⒉ 另一种是物体本身不发光,而是反射的光产生 十六进制颜色码 的颜色,比如看报纸和杂志上的颜色. 我们又知道任 ...

  3. python 遍历字典

    dict={"a":"apple","b":"banana","o":"orange&qu ...

  4. 【网络流24题】 No.5 圆桌问题 (多重匹配)

    [题意] 假设有来自 n 个不同单位的代表参加一次国 际会议.每个单位的代表数分别为r i ni , = 1,2, .会议餐厅共有 m 张餐桌,每张餐桌可容纳 ci (i = 1,2, , m) 个 ...

  5. POJ - 3264 Balanced Lineup 线段树解RMQ

    这个题目是一个典型的RMQ问题,给定一个整数序列,1~N,然后进行Q次询问,每次给定两个整数A,B,(1<=A<=B<=N),求给定的范围内,最大和最小值之差. 解法一:这个是最初的 ...

  6. 【HDOJ】1242 Rescue

    BFS+优先级队列. #include <iostream> #include <cstdio> #include <cstring> #include <q ...

  7. redhat 6.5 使用其它Linux镜像源的yum源

    最近在虚拟机里装了rhel_6.5_x86_64,发现竟然不自带g++,没办法只好 “yum install gcc-c++”,无奈失败,原因是redhat的yum是收费的... 于是打算怒装其它免费 ...

  8. Linux Kernel 'sctp_v6_xmit()'函数信息泄露漏洞(CVE-2013-4350)

    漏洞版本: Linux kernel 漏洞描述: BUGTRAQ ID: 62405 CVE(CAN) ID: CVE-2013-4350 Linux Kernel是Linux操作系统的内核. Lin ...

  9. java基于xml配置的通用excel单表数据导入组件(五、Action处理类)

    package xxxxxx.manage.importexcel; import java.io.File; import java.util.HashMap; import java.util.M ...

  10. 【转】BCSphere入门教程01:Immediate Alert--不错

    原文网址:http://www.ituring.com.cn/article/117570 写在前面 智能硬件开发的起点是智能硬件,在本教程中的每一章节,首先会列出您的蓝牙智能硬件所需要支持的Serv ...