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 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)的更多相关文章
- 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 ...
- 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 ...
- PAT A 1014. Waiting in Line (30)【队列模拟】
题目:https://www.patest.cn/contests/pat-a-practise/1014 思路: 直接模拟类的题. 线内的各个窗口各为一个队,线外的为一个,按时间模拟出队.入队. 注 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- PAT甲题题解-1014. Waiting in Line (30)-模拟,优先级队列
题意:n个窗口,每个窗口可以排m人.有k为顾客需要办理业务,给出了每个客户的办理业务时间.银行在8点开始服务,如果窗口都排满了,客户就得在黄线外等候.如果有一个窗口用户服务结束,黄线外的客户就进来一个 ...
- 【PAT Advanced Level】1014. Waiting in Line (30)
简单模拟题,注意读懂题意就行 #include <iostream> #include <queue> using namespace std; #define CUSTOME ...
随机推荐
- sql over开窗函数
1.使用over子句与rows_number()以及聚合函数进行使用,可以进行编号以及各种操作.而且利用over子句的分组效率比group by子句的效率更高. 2.在订单表(order)中统计中,生 ...
- 使你的 Google Summer of Code 建议被接收的5个技巧
本文翻译自:http://www.di.ens.fr/~baghdadi/TXT_blog/5_advices_to_get_your_proposal_accepted.lyx.html 本文讲的主 ...
- hdu 4421 Bit Magic
[题意] 这个函数是给A求B的,现在给你B,问你是否能有A的解存在. [2-SAT解法] 对于每个A[i]的每一位运行2-sat算法,只要跑到强连通就可以结束,应为只要判断是否有解,后面拓扑求解就不需 ...
- hdu 4494 最小费用流
思路:这题我在下午重现的时候就用的费用流做,可是各种悲催的超时,只是我一开始的那种建图方式多了一个二分查找. 戏剧性的是,求距离的返回值写成int型了,CodeBlock编译器又没有警告,然后就WA啊 ...
- json2.js 的使用
转载自:http://www.cnblogs.com/youring2/archive/2013/03/01/2938850.html -------------------------------- ...
- 【网络收集】order by 自定义排序
使用order by排序,有时候不是根据字符或数字顺序,而是根据实际要求排序. 例如有客户A,B,C,我希望排序结果是B,C,A,那么就要通过自定义的规则排序. 第一种方法,可以构造一张映射表,将客户 ...
- JavaScript之放大镜效果
在网上也浏览过许多关于JavaScript放大镜效果的文章,有的代码解释得些隐晦难懂,看的我头有点晕晕的╮(╯﹏╰)╭,我的心情是这样的: 吐槽完了,我们动动小鼠标,当鼠标经过下面这张美女图片时就实现 ...
- SQL 复制订阅 异常后 强制删除
最近做数据库同步备份工作,将 主库 通过SQLService 自带的 [复制] 订阅出去后,因为 订阅方(从库) 发生异常,主库 无法确定 从库的订阅,就想清理了,订阅重新做同步,结果.....主库上 ...
- iOS-设置启动图片
启动图片设置 设置方法一 这种方法里,默认模拟器和真机的尺寸和启动图片的尺寸相同. 通过美工提供各种尺寸的启动图片来适配屏幕的大小.这种方法要求美工提供各种屏幕大小的图片. 步骤如下: 1.如图所示, ...
- sql server 查找字段上的约束
1. 当字段没有默认值或者约束的时候可以使用: alter table [table_name] drop column [column_name] 来删除. 当有默认值的时候应该先删除默认值,然后再 ...