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 ...
随机推荐
- APP-SERVICE-SDK:setStorageSync:fail;at page/near/pages/shops/shops page lifeCycleMethod onUnload function
APP-SERVICE-SDK:setStorageSync:fail;at page/near/pages/shops/shops page lifeCycleMethod onUnload fun ...
- 在JavaEE中使用Mybatis框架
MyBatis 使用简单的 XML 或注解用于配置和原始映射,将接口和 Java 的 POJOs(Plain Old Java Objects,普通的 Java 对象)映射成数据库中的记录.每个MyB ...
- 认识SQL
一.SQL介绍 SQL 是用于访问和处理数据库的标准的计算机语言. i.What? SQL 指结构化查询语言 SQL 使我们有能力访问数据库 SQL 是一种 ANSI 的标准计算机语言 ii.How? ...
- dede:field name=’position’标签调用 主页改成英文Home和改变符号
在用dede:field name=’position’ 这个标签的时候我们调用的这个就是中文的,出现的是主页>+相应的栏目 ,那么这个问题怎么改成英文的呢?有好多大虾都说找到dede安装目录 ...
- wget 下载网页
如有转载,不胜荣幸.http://www.cnblogs.com/aaron-agu/ wget --http-user=username --http-passwd=password http:/w ...
- Pulse-per-second (PPS) Signal Interfacing
Some radio clocks and related timekeeping gear have a pulse-per-second (PPS) signal that can be used ...
- 转载:关于JESD204B转换器与FPGA匹配的设计关键点
http://www.dzsc.com/data/2014-11-27/107442.html 随着更多的模数转换器(ADC)和数模转换器(DAC)支持最新的JESD204B串行接口标准,出现了FPG ...
- JavaScript Decorators 的简单理解
Decorators,装饰器的意思, 所谓装饰就是对一个物件进行美化,让它变得更漂亮.最直观的例子就是房屋装修.你买了一套房子,但是毛坯房,你肯定不想住,那就对它装饰一下,床,桌子,电视,冰箱等一通买 ...
- 牛客网-2018年湘潭大学程序设计竞赛-F
题目链接:https://www.nowcoder.com/acm/contest/105/F 解题思路:这道题第一眼直接思路就是搜索,但想了半天没想到有什么好办法搜,然后就转成最短路写了, 因为多入 ...
- U盘快速启动热键
各个品牌电脑U盘快速启动热键如下: