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 (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, customer​1​​ is served at window​1​​while customer​2​​ is served at window​2​​. Customer​3​​ will wait in front of window​1​​ and customer​4​​ will wait in front of window​2​​. Customer​5​​ will wait behind the yellow line.

At 08:01, customer​1​​ is done and customer​5​​ enters the line in front of window​1​​ since that line seems shorter now. Customer​2​​ will leave at 08:02, customer​4​​ at 08:06, customer​3​​ at 08:07, and finally customer​5​​ at 08:10.

Input Specification:

Each input file contains one test case. Each case starts with a line containing 4 positive integers: N (≤, number of windows), M (≤, the maximum capacity of each line inside the yellow line), K (≤, number of customers), and Q (≤, number of customer queries).

The next line contains K positive integers, which are the processing time of the Kcustomers.

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 Specification:

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

题的大意:
N个窗口,每个窗口线内排队M个人,其他人在线外等候
哪个窗口有空缺,那么就上那个窗口去排队
当有多个窗口空缺,则选择小号排队
问每个人从早上8.00到他办完业务的具体时间

有个点得注意一下,就是当有个人排队在16:59开始办业务,
就算他要办1000分钟的业务,他也是算能办上业务的,不应输出sorry

 #include<iostream>
#include <vector>
#include <queue>
using namespace std; int N, M, K, Q; int main()
{
cin >> N >> M >> K >> Q;
vector<queue<int>>windows(N);//N个窗口
vector<int>endTime(K + );
vector<bool>Sorry(K + , false);//若前面那个人的业务办理时间超过下班时间,那么你是排不上的
int a, time;
for (int i = ; i < K; ++i)
{
cin >> a;
if (i < N * M)//先将窗口的位子按序排满,存的是该人完成业务的时间
{
if (windows[i%N].size() > )
{
time = windows[i%N].back() + a;
windows[i%N].push(time);
Sorry[i + ] = windows[i%N].back() >= ? true : false;
}
else
{
time = a;
windows[i%N].push(a);
}
}
else//线外的人选择窗口排队
{
int minTime = windows[].front(), index = ;
for (int j = ; j < N; ++j)//找到最先出现空位的窗口,然后去选择该窗口排队
{
if (minTime > windows[j].front())
{
index = j;
minTime = windows[j].front();
}
}
Sorry[i + ] = windows[index].back() >= ? true : false;
time = windows[index].back() + a;
windows[index].pop();//排完对队就离开
windows[index].push(time);//排队
}
endTime[i + ] = time;
} for (int i = ; i < Q; ++i)
{
cin >> a;
time = endTime[a];
if (Sorry[a])
printf("Sorry\n");
else
printf("%02d:%02d\n", + time / , time % );
}
return ;
}
 

PAT甲级——A1014 Waiting in Line的更多相关文章

  1. PAT甲级1014. Waiting in Line

    PAT甲级1014. Waiting in Line 题意: 假设银行有N个窗口可以开放服务.窗前有一条黄线,将等候区分为两部分.客户要排队的规则是: 每个窗口前面的黄线内的空间足以包含与M个客户的一 ...

  2. 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 ...

  3. 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 ...

  4. A1014. Waiting in Line

    Suppose a bank has N windows open for service. There is a yellow line in front of the windows which ...

  5. PAT A 1014. Waiting in Line (30)【队列模拟】

    题目:https://www.patest.cn/contests/pat-a-practise/1014 思路: 直接模拟类的题. 线内的各个窗口各为一个队,线外的为一个,按时间模拟出队.入队. 注 ...

  6. PAT甲级题解分类byZlc

    专题一  字符串处理 A1001 Format(20) #include<cstdio> int main () { ]; int a,b,sum; scanf ("%d %d& ...

  7. PAT Waiting in Line[转载]

    //转自:https://blog.csdn.net/apie_czx/article/details/45537627 1014 Waiting in Line (30)(30 分)Suppose ...

  8. PAT 1014 Waiting in Line (模拟)

    1014. Waiting in Line (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Suppo ...

  9. PAT甲级题解(慢慢刷中)

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6102219.html特别不喜欢那些随便转载别人的原创文章又不给 ...

随机推荐

  1. Android按钮绑定四种方式

    public class MainActivity extends Activity implements OnClickListener{ @Override protected void onCr ...

  2. socket远程执行命令

    两个脚本模拟远程执行命令 cmd_server.py import socket import subprocess # 运行系统命令 sk = socket.socket() addess = (' ...

  3. maven配置步骤

    仅做操作手册使用,一些操作频率较高的步骤已省略 第一步:度娘下载maven并解压 此处使用了apache-maven-3.2.5-bin.zip, 解压后复制到了D盘的D:\maven\apache- ...

  4. VS2017+QT5.12环境配置与动态链接库的生成

    最近需要重新编译一个DLL动态链接库,由于源码中包含了QT代码,所以现在需要配置VS+QT环境. 本人系统环境:Win10 64位 一.安装 Visual Studio 2017软件下载安装教程:ht ...

  5. sparkJavaApi逐个详解

    说明:掌握spark的一个关键,就是要深刻理解掌握RDD各个函数的使用场景,这样我们在写业务逻辑的时候就知道在什么时候用什么样的函数去实现,得心应手,本文将逐步收集整理各种函数原理及示例代码,持续更新 ...

  6. 浅谈web应用的高可用

    1.熟悉几个组件 1.1.apache     —— 它是Apache软件基金会的一个开放源代码的跨平台的网页服务器,属于老牌的web服务器了,支持基于Ip或者域名的虚拟主机,支持代理服务器,支持安全 ...

  7. Linux 实用指令(5)--组管理和权限管理

    目录 组管理和权限管理 1 Linux组基本介绍 2 文件/目录 所有者 2.1 查看文件的所有者 2.2 修改文件所有者 3 组的创建 3.1 基本指令 3.2 应用实例 4 文件/目录 所在组 4 ...

  8. Luogu P2042 [NOI2005]维护数列(平衡树)

    P2042 [NOI2005]维护数列 题意 题目描述 请写一个程序,要求维护一个数列,支持以下\(6\)种操作:(请注意,格式栏中的下划线'_'表示实际输入文件中的空格) 输入输出格式 输入格式: ...

  9. vc 获取窗口标题GetWindowText

    今天在写一个模块,具体功能是想时刻监控用户当前活动窗口,需要获取窗口标题以及其它相关信息,记得API GetWindowText就是用来做这个的,结果试了半天,有的获取成功了有的获取失败了,而且有关汉 ...

  10. 踩坑记-java mysql 新增获取主键、DIY主键、UUID

    java mysql 获取主键.DIY主键.UUID,简单粗暴,代码如下: mapper.xml insert id="add" parameterType="com.x ...