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. epoll和select区别

    先说下本文框架,先是问题引出,然后概括两个机制的区别和联系,最后介绍每个接口的用法 一.问题引出 联系区别 问题的引出,当需要读两个以上的I/O的时候,如果使用阻塞式的I/O,那么可能长时间的阻塞在一 ...

  2. whoosh使用笔记

    1. whoosh安装 pip install Whoosh 2. 添加索引 第一步:生成schema 第二步:根据schema生成index.index就是一个目录中的一堆文件  (针对某个目录,调 ...

  3. 在虚拟机的linux中利用VMware Tools实现与windows共享文件

        很多人都知道安装"VMware Tools"可以实现与windows共享,但是其实它的功能远不止此.安装了"VMware Tools"后,虚拟机的网络. ...

  4. KVC - 键值编码

    [基本概念] 1.键值编码是一个用于间接访问对象属性的机制,使用该机制不需要调用存取方法和变量实例就可访问对象属性. 2.键值编码方法在OC非正式协议(类目)NSKeyValueCoding中被声明, ...

  5. nginx处理静态资源的配置

    修改nginx.conf文件,用于nginx处理静态资源. 主要配置如下(在server配置中加入location配置即可): server { listen 80; server_name 123. ...

  6. Xcode8和iOS10的适配问题

    本文转自:http://www.jianshu.com/p/90d5323cf510 =================== 一.遇到的问题 1.权限以及相关设置 iOS10系统下调用系统相册.相机功 ...

  7. form表单提交的方法

    最近研究了下html中,form保单提交的几种方法,现与大家分享一下(注:网上可能已经有好多版本了,这里自己写下来做个总结了,哈!): 方法一:利用form的onsubmit()函数(经常使用) &l ...

  8. 配置PhpStorm调试PHP

    配置PhpStorm调试PHP 第一步:配置 XDebug 下载安装XDebug到本地环境(参考:Zend Studio 9.x + xampp + XDebug 调试环境安装详解),打开php.in ...

  9. 解决wordpress上传的文件尺寸超过 php.ini 中定义的 upload_max_filesize 值。

    上传的文件尺寸超过 php.ini 中定义的 upload_max_filesize 值. 解决方法:修改/etc/php5/apache2/php.ini文件中的 post_max_size = 6 ...

  10. Android Studio 使用笔记:Git 的配置和第一次提交到仓库

    Git客户端网址:http://git-scm.com/download/ 根据自己的使用平台下载对应的客户端.这里以Mac系统为例,当客户端软件安装配置完毕后,打开AS的配置面板,找到Git的选项 ...