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 ...
随机推荐
- MyBatis源码分析1 参数映射分析
首先我们拿出之前的代码,在如图位置打上断点,开始调试 我们规定了一个mapper接口,而调用了mapper接口的getEmpByIdAndLastName,我们并没有实现这个接口,这是因为Mybati ...
- java之序列化
详细内容 连接https://blog.csdn.net/qq_27093465/article/details/78544505 Java 之 Serializable 序列化和反序列化的概念,作用 ...
- Handler主线程子线程之间的互相通信
Handler主线程子线程之间的互相通信 package com.wyl.dansnote; import android.app.Activity; import android.os.Bundle ...
- mysql 如何查看sql语句执行时间和效率
查看执行时间 1 show profiles; 2 show variables;查看profiling 是否是on状态: 3 如果是off,则 set profiling = 1: 4 执行自己的s ...
- mysql逻辑架构
逻辑架构图 MySQL有点与众不同,它的逻辑架构可以在多种不同的场景中应用并发挥良好的作用.主要体现在存储引擎的架构上,插件式的存储引擎架构将查询处理和其他的系统任务以及数据的存储提取相分离.这种架构 ...
- Python自动化测试之selenium从入门到精通
1. 安装selenium 首先确保python安装成功,输入python -V 在windows下使用pip安装selenium,详情如图所示: 在ubuntu下使用pip install sele ...
- 一、hadoop部署
一.Java环境 yum 安装方式安装 1.搜索JDK安装包 yum search java|grep jdk 2.安装 yum install java-1.8.0-openjdk-src.x86_ ...
- 三、K8S成功
kubeadm join 172.17.149.114:6443 --token yjogpa.kk85u2i4n5rt1omq --discovery-token-ca-cert-hash sha2 ...
- Windows & RabbitMQ:集群(clustering) & 高可用(HA)
描述:我们需要配置三台服务器:ServerA, ServerB, ServerC 注意事项: 所有的服务器的Erlang版本,RabbitMQ版本必须一样 服务器名大小写敏感 Step 1:安装Rab ...
- rand和randn
1,rand 生成均匀分布的伪随机数.分布在(0~1)之间 主要语法:rand(m,n)生成m行n列的均匀分布的伪随机数 rand(m,n,'double')生成指定精度的均匀分布的伪随机数,参数还可 ...