A1014. Waiting in Line
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 customers 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 window1while 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<cstdio>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
using namespace std;
typedef struct{
queue<int> qu;
int nowT;
int endFirst;
}info;
info window[];
int N, M, K, Q;
int costum[], req[], leave[];
int main(){
scanf("%d%d%d%d", &N, &M, &K, &Q);
for(int i = ; i < K; i++){
scanf("%d", &costum[i]);
}
for(int i = ; i < Q; i++){
scanf("%d", &req[i]);
}
for(int i = ; i < N; i++){
window[i].nowT = * ;
}
for(int i = ; i < K; i++){
int index = -, minLine = ;
for(int j = ; j < N; j++){
if(window[j].qu.size() < minLine && window[j].qu.size() < M){
index = j;
minLine = window[j].qu.size();
}
}
if(index != -){
window[index].qu.push(i);
}else{
int popIndex = -, minTime = ;
for(int j = ; j < N; j++){
window[j].endFirst = window[j].nowT + costum[window[j].qu.front()];
if(window[j].endFirst < minTime){
popIndex = j;
minTime = window[j].endFirst;
}
}
window[popIndex].nowT = window[popIndex].endFirst;
leave[window[popIndex].qu.front()] = window[popIndex].endFirst;
window[popIndex].qu.pop();
window[popIndex].qu.push(i);
}
}
for(int i = ; i < N; i++){
while(window[i].qu.empty() == false){
int Ci = window[i].qu.front();
leave[Ci] = window[i].nowT + costum[Ci];
window[i].nowT = leave[Ci];
window[i].qu.pop();
}
}
for(int i = ; i < Q; i++){
req[i]--;
if(leave[req[i]] - costum[req[i]] >= * ){
printf("Sorry\n");
}else{
printf("%02d:%02d\n", leave[req[i]] / , leave[req[i]] % );
}
}
cin >> N;
return ;
}
总结:
1、题意:有N个窗口,每个窗口可以排队M个人,有K个顾客来办理。每次顾客都选择最短的队伍排队。
2、由于顾客优先选择队列人少的地方排队而不是提前结束服务的队伍排队,所以需要保留队列信息。当存在不满的队列时,找一个最短的队列,将顾客加入。当队列都满时,选择一个能最早服务完一个人的队列,则该队列就是最短的队列,服务完队首元素后将顾客加入。
3、题目中要求的是在5点后没有开始服务的人无法被服务,而非5点后没有完成业务的人无法被服务。
A1014. Waiting in Line的更多相关文章
- PAT A1014 Waiting in Line (30 分)——队列
Suppose a bank has N windows open for service. There is a yellow line in front of the windows which ...
- PAT甲级——A1014 Waiting in Line
Suppose a bank has N windows open for service. There is a yellow line in front of the windows which ...
- PAT Waiting in Line[转载]
//转自:https://blog.csdn.net/apie_czx/article/details/45537627 1014 Waiting in Line (30)(30 分)Suppose ...
- PTA (Advanced Level) 1014 Waiting in Line
Waiting in Line Suppose a bank has N windows open for service. There is a yellow line in front of th ...
- PAT甲级1014. Waiting in Line
PAT甲级1014. Waiting in Line 题意: 假设银行有N个窗口可以开放服务.窗前有一条黄线,将等候区分为两部分.客户要排队的规则是: 每个窗口前面的黄线内的空间足以包含与M个客户的一 ...
- PAT 1014 Waiting in Line (模拟)
1014. Waiting in Line (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Suppo ...
- pat1014. Waiting in Line (30)
1014. Waiting in Line (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Suppo ...
- 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 ...
随机推荐
- SAP配置BOM的适用范围
配置BOM中定义属性,单纯的编码要搞死人: 适合小批量周期短多品种
- CentOS7下Nginx搭建反向代理,并使用redis保存session
1.启动两个tomcat,端口分别为8080,8081 2.配置nginx,vim /usr/local/nginx/conf/nginx.conf 添加如下配置: 3.启动nginx或热加载 启动: ...
- Spring 的java 配置方式
Java配置是Spring4.x推荐的配置方式,可以完全替代xml配置. 1.1@Configuration 和 @Bean Spring的Java配置方式是通过 @Configuration 和 @ ...
- linux audit审计(5)--audit规则配置
audit可以配置规则,这个规则主要是给内核模块下发的,内核audit模块会按照这个规则获取审计信息,发送给auditd来记录日志. 规则类型可分为: 1.控制规则:控制audit系统的规则: 2.文 ...
- Yii的数值比较验证器
该验证器比对两个特定输入值之间的关系 是否与 operator 属性所指定的相同. compareAttribute:用于与原属性相比对的属性名称. 当该验证器被用于验证某目标属性时, 该属性会默认为 ...
- layui 提交表格不验证
form.on('submit(filter_save)', function (data) { 后面查找发现是提交按钮要放在form里面
- sun.misc.BASE64Encoder----》找不到jar包的解决方法
1.右键项目->属性->java bulid path->jre System Library->access rules->resolution选择accessible ...
- 学习 Spring (三) Bean 的配置项 & 作用域
Spring入门篇 学习笔记 配置项 Id: 整个 IoC 容器中的唯一标识 Class: 具体实例化的类(必须配置项) Scope: 作用域 Constructor arguments: 构造器参数 ...
- MySQL参数调优
目录 连接相关参数 文件相关参数 缓存相关参数 MyISAM参数 InnoDB参数 连接相关参数 max_connections 允许客户端并发连接的最大数量,默认值是151,一般将该参数设置为50 ...
- .net mvc 基类属性覆盖问题
一,问题是这样的 我使用.net mvc设计架构时, 为了方便大家的获取UserInfo信息, 把UserInfo对象,放在了自定义的基类BaseController中, 二,问题出现了 我发觉多个人 ...