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. js 遍历json对象

    //方法一: var data=[{name:"a",age:12},{name:"b",age:11},{name:"c",age:13} ...

  2. Couldn't get lock for %t/vertx.log

    今天在启动vertx框架的项目时,报“Couldn't get lock for %t/vertx.log”的错误. 解决方案: 1,找出vertx.log的目录.一般在(C:\Users\Admin ...

  3. ecshop改造读写分离

    前两天配置好了mysql主从方式,今天就拿ecshop练习读写分离.以下代码仅供学习参考,不成熟的地方,还需完善. config.php <?php $db_name = "ecsho ...

  4. WPF中的字体改善

    WPF4对字体渲染做了很大的改善,增加了TextOptions属性,该属性可以设置TextFormattingMode,TextRenderingMode,TextHintingMode 1.Text ...

  5. MOSFET管应用总结

    /* *本文转载自互联网,仅供个人学习之用,请勿用于商业用途. */ 在使用MOS管设计开关电源或者马达驱动电路的时候,大部分人都会考虑MOS的导通电阻,最大电压等,最大电流等,也有很多人仅仅考虑这些 ...

  6. ms-on-input

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  7. IT专业人士如何更有效的学习专业知识

    查看: http://www.cnblogs.com/suizhouqiwei/archive/2010/05/17/1737265.html 书:http://www.cnblogs.com/wxi ...

  8. C#中值参数的使用实例

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 函数的参 ...

  9. uva 1482 - Playing With Stones

    对于组合游戏的题: 首先把问题建模成NIM等经典的组合游戏模型: 然后打表找出,或者推出SG函数值: 最后再利用SG定理判断是否必胜必败状态: #include<cstdio> #defi ...

  10. js template

    http://garann.github.io/template-chooser/ http://www.gbin1.com/technology/javascript/20120917-javasc ...