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 ...
随机推荐
- 0. SQL Server监控清单
数据库服务器的监控可大致分为两类: (1) 状态监控:数据库服务器有没有在健康地运行? (2) 性能监控:健康运行的同时,有没有性能问题?可不可以更快些? 一. 服务器 1. 状态监控 (1) 服务器 ...
- uva 12284 直接判断
思路:见代码 #include<iostream> #include<cstring> #include<cstdio> #include<algorithm ...
- some smart
1.ca.laplanete.mobile.pageddragdropgridhttps://github.com/mrKlar/PagedDragDropGridPagedDragDropGrid ...
- 如果AlertView输入框为空,则禁止点击确定按钮
//UIAlertView的代理方法(创建UIAlertView之后,copy此代理方法即可) - (BOOL)alertViewShouldEnableFirstOtherButton:(UIAle ...
- Linux 内核模块可选信号
一 . 内核模块可选信号 1 . 模块申明 (1). MODULE_LICENSE(遵守的协议) 申明该模块遵守的许可证协议,如:“GPL”."GPL V2" (2). MODUL ...
- AspNetPager学习使用1
今天开始研究使用AspNetPager 首先贴上下载链接:http://www.webdiyer.com/aspnetpager/downloads/ 在下载链接中,作者已经提供了使用方法.在这里,本 ...
- CSS之密码强度检测
输入密码后单击空白处即可检测. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "ht ...
- sql调用方法精简
<%If IsArray(proList) Then%> <UL class="product-ul"> <%For x=0 to Ubound(pr ...
- 验证证书的安装之外部用户PC
背景:使用一个域外的用户进行登录并验证 1. 用户登录浏览器下载CA证书或者证书链 2. 下载 3. 安装证书 4. ...
- 集合框架学习之Guava Collection
开源工具包: Guava : Google Collection Apache:Commons Collecton 1.1 Google Collections Guava:google的工程师利用传 ...