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
 #include<stdio.h>
#include<vector>
using namespace std;
struct cus
{
int id;
int cost,h,m;
bool is;
}; cus CUS[]; struct window
{
window():h(),m(){}
int h,m;
bool late;
vector<cus> line;
}; window wins[]; window add(window a,int n)
{
a.m += n;
a.h += (a.m/);
a.m = a.m%;
return a;
} bool smaller(window a, window b)
{
if(a.h != b.h)
{
return a.h < b.h;
}
return a.m < b.m;
} int min_id(int n)
{
window MIN;
MIN.h = ;
int id = -;
for(int i = ; i< n ; ++i)
{
if((!wins[i].late) && wins[i].line.size() > && smaller(add(wins[i],wins[i].line[].cost),MIN))
{
MIN = add(wins[i],wins[i].line[].cost);
id = i;
}
}
return id;
} int main()
{
int win_num,max_num,k,q,id_cnt = ;
scanf("%d%d%d%d",&win_num,&max_num,&k,&q);
cus ctem;
for(int i = ; id_cnt <= k && i < max_num;++i)
{
for(int j = ;id_cnt <= k && j < win_num;++j)
{
scanf("%d",&ctem.cost);
ctem.id = id_cnt++;
wins[j].line.push_back(ctem);
}
}
for(;id_cnt <= k;++id_cnt)
{
scanf("%d",&ctem.cost);
int index = min_id(win_num);
if(wins[index].h >= )
{
wins[index].late = ;
continue;
}
window wtem = add(wins[index],wins[index].line[].cost);
wins[index].h = CUS[wins[index].line[].id].h = wtem.h;
wins[index].m = CUS[wins[index].line[].id].m = wtem.m;
CUS[wins[index].line[].id].is = ;
wins[index].line.erase(wins[index].line.begin());
ctem.id = id_cnt;
wins[index].line.push_back(ctem); }
int index = min_id(win_num);
while(index!= -)
{
if(wins[index].h >= )
{
wins[index].late = ;
index = min_id(win_num);
continue;
}
window wtem = add(wins[index],wins[index].line[].cost);
wins[index].h = CUS[wins[index].line[].id].h = wtem.h;
wins[index].m = CUS[wins[index].line[].id].m = wtem.m;
CUS[wins[index].line[].id].is = ;
wins[index].line.erase(wins[index].line.begin());
index = min_id(win_num);
}
int id_tem;
for(int i = ;i < q ; ++i)
{
scanf("%d",&id_tem);
if(!CUS[id_tem].is)
{
printf("Sorry\n");
}
else
{
printf("%02d:%02d\n",CUS[id_tem].h,CUS[id_tem].m);
}
}
return ;
}

1014. Waiting in Line (30)的更多相关文章

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

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

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

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

  4. 1014 Waiting in Line (30)(30 point(s))

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

  5. 1014 Waiting in Line (30)(30 分)

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

  6. 1014 Waiting in Line (30 分)

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

  7. PTA 1014 Waiting in Line (30分) 解题思路及满分代码

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

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

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

  9. 【PAT Advanced Level】1014. Waiting in Line (30)

    简单模拟题,注意读懂题意就行 #include <iostream> #include <queue> using namespace std; #define CUSTOME ...

随机推荐

  1. 仿jQuery中undelegate()方法功能的函数

    //跨浏览器事件绑定 function addEvent(obj,type,fn){ if(typeof obj.removeEventListener !='undefined'){ /////// ...

  2. Problem:Minesweeper Master

    Google code jam Qualification Round 2014 题目链接:https://code.google.com/codejam/contest/dashboard?c=29 ...

  3. hdu 3585 二分+最大团

    题目:给出平面上n个点,现在找m个点,并且使得这m个点最近的两个最远. 分析:显然这满足二分的性质,二分答案,根据点距离需要大于等于二分值重新构造新图,则问题变成了:在新图中找出满足所有点对之间的距离 ...

  4. 写入数据到Plist文件中时,第一次要创建一个空的数组,否则写入文件失败

    #pragma mark - 保存数据到本地Plist文件中 - (void)saveValidateCountWithDate:(NSString *)date count:(NSString *) ...

  5. poj 3979 分数加减法

    分数加减法 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13666   Accepted: 4594 Descriptio ...

  6. WGS84坐标系下,经纬度如何换算成米

    参考博客:显示瓦片地图  http://www.cnblogs.com/rhinoxy/p/4995731.html 注意:这里的计算方法精度相差比较大,不满足精确计算的需要. 需要理解的GIS概念: ...

  7. HTML CSS编码规范(黄金定律)

    HTML 语法 用两个空格来代替制表符(tab) -- 这是唯一能保证在所有环境下获得一致展现的方法. 嵌套元素应当缩进一次(即两个空格). 对于属性的定义,确保全部使用双引号,绝不要使用单引号. 不 ...

  8. AngularJS尝鲜一

    第一个小例子,体验一下: <!DOCTYPE html> <html> <head> <title>Index</title> </h ...

  9. [GeekBand]C++高级编程技术(2)

    本篇笔记主要分为两个主要部分,第一部分关于对象模型,第二部分是关于new和delete的更加深入的学习. 一.对象模型 关于vptr(虚指针)和vtbl(虚函数表) 只要用到了虚函数,对象中就会多一个 ...

  10. java8个基本类型和它们所占的字节数

    byte : 1字节 short : 2字节 int : 4字节 float :4字节 long : 8字节 double : 8字节 char :2字节 boolean : 1字节 补充说明:在实际 ...