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 ...
随机推荐
- Android Activity的启动过程
文章编辑的太长了,请移步我的csdn博客:http://blog.csdn.net/xyh269 Android Activity的启动过程原文链接:http://blog.csdn.net/xyh2 ...
- android studio还不错
今天体验了哈 Android Studio,还不错同Elipse类似
- uva 101 POJ 1208 The Blocks Problem 木块问题 vector模拟
挺水的模拟题,刚开始题目看错了,poj竟然过了...无奈.uva果断wa了 搞清题目意思后改了一下,过了uva. 题目要求模拟木块移动: 有n(0<n<25)快block,有5种操作: m ...
- nginx lua mysql redis设置
最近公司网站改版,程序和数据库全部用新版,旧版的数据要导入,旧网站的30万条数据url要全部重定向到新版网站,正好前段时间在学习nginx+lua+mysql+memcache(redis),找资料真 ...
- 【Dijkstra】
[摘自]:华山大师兄,推荐他的过程动画~ myth_HG 定义 Dijkstra算法是典型的单源最短路径算法,用于计算一个节点到其他所有节点的最短路径.主要特点是以起始点为中心向外层层扩展,直到扩 ...
- Event Handling in Spring
Spring内置的event有 1.ContextRefreshedEvent This event is published when the ApplicationContext is eithe ...
- 51nod-1686 第K大区间(二分+尺取法)
题目链接: 第K大区间 基准时间限制:1 秒 空间限制:131072 KB 定义一个区间的值为其众数出现的次数.现给出n个数,求将所有区间的值排序后,第K大的值为多少. Input 第一行两个数 ...
- 添加iPhone设备的udid之后,重新生成开发证书(Development)
选择Provisioning profiles-Development-添加 ,如图:
- flv视频播放器代码
<div class="txt1"> <script type="text/javascript"> var swf_width=307 ...
- 简单的表单验证插件(Jquery)
在做web开发的时候经常遇到表单验证问题,表单验证一般有客户端验证和服务器端验证,这个验证插件仅仅能满足我的项目中的基本需求的. Validate_Tools.js function Validate ...