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. 补充:tableView优化总结

    tableView优化方式总结 (说明:一下只是我自己的小总结,会有不足,望大神指正,多谢大家了) 1 缓存 cell 的行高.目的方便第二遍访问 cell. 2 减少图片的blend 操作.包括:设 ...

  2. Pull解析-解析xml文件

    首先需要导入jar包:kxml2-2.2.2.jar 例程: main: /** * pull解析 * * @author my * */ public class DemoParserStudent ...

  3. <c:forEach> 详解

    <c:forEach>标签用于通用数据循环,它有以下属性 属 性 描 述 是否必须 缺省值 items 进行循环的项目 否 无 begin 开始条件 否 0 end 结束条件 否 集合中的 ...

  4. mac下修改mysql登录密码

    mysql版本5.7.9 在mac终端下修改mysql用户登录密码 终端命令如下: update mysql.user set authentication_string=PASSWORD(" ...

  5. jQuery:节点(插入,复制,替换,删除)操作

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  6. BZOJ 3083: 遥远的国度 dfs序,树链剖分,倍增

    今天再做一天树的题目,明天要开始专攻图论了.做图论十几天之后再把字符串搞搞,区域赛前再把计几看看. 3083: 遥远的国度 Time Limit: 10 Sec  Memory Limit: 128 ...

  7. BZOJ 1146: [CTSC2008]网络管理Network 树链剖分+线段树+平衡树

    1146: [CTSC2008]网络管理Network Time Limit: 50 Sec  Memory Limit: 162 MBSubmit: 870  Solved: 299[Submit] ...

  8. 第二章 Background & Borders 之 Multiple borders

    2. Multiple Boerders 多边框 在工作中我们可能会遇到给盒子外层实现多个边框.如以下效果: 方法1: 实现这个效果,其实很简单,使用CSS3 的box-shadow属性,先看看box ...

  9. Warning: Permanently added '...' (RSA) to the list of known hosts --Windows下git bash 警告处理

    原链接地址 StackOverflow 处理方法: 创建文件~/.ssh/config, 此处对应windows当前用户目录下的.ssh文件夹 增加如下语句 UserKnownHostsFile ~/ ...

  10. SERVER 2012 R2 core域环境下批量创建用户

      Write by xiaoyang 转载请注明出处 步骤一:创建域 基本配置 1.         输入命令进入配置 2.         输入8进入网络配置 3.         选择要配置的网 ...