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:

  1. 2 2 7 5
  2. 1 2 6 4 3 534 2
  3. 3 4 5 6 7

Sample Output:

  1. 08:07
  2. 08:06
  3. 08:10
  4. 17:00
  5. Sorry

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

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

  1. #include<iostream>
  2. #include <vector>
  3. #include <queue>
  4. using namespace std;
  5.  
  6. int N, M, K, Q;
  7.  
  8. int main()
  9. {
  10. cin >> N >> M >> K >> Q;
  11. vector<queue<int>>windows(N);//N个窗口
  12. vector<int>endTime(K + );
  13. vector<bool>Sorry(K + , false);//若前面那个人的业务办理时间超过下班时间,那么你是排不上的
  14. int a, time;
  15. for (int i = ; i < K; ++i)
  16. {
  17. cin >> a;
  18. if (i < N * M)//先将窗口的位子按序排满,存的是该人完成业务的时间
  19. {
  20. if (windows[i%N].size() > )
  21. {
  22. time = windows[i%N].back() + a;
  23. windows[i%N].push(time);
  24. Sorry[i + ] = windows[i%N].back() >= ? true : false;
  25. }
  26. else
  27. {
  28. time = a;
  29. windows[i%N].push(a);
  30. }
  31. }
  32. else//线外的人选择窗口排队
  33. {
  34. int minTime = windows[].front(), index = ;
  35. for (int j = ; j < N; ++j)//找到最先出现空位的窗口,然后去选择该窗口排队
  36. {
  37. if (minTime > windows[j].front())
  38. {
  39. index = j;
  40. minTime = windows[j].front();
  41. }
  42. }
  43. Sorry[i + ] = windows[index].back() >= ? true : false;
  44. time = windows[index].back() + a;
  45. windows[index].pop();//排完对队就离开
  46. windows[index].push(time);//排队
  47. }
  48. endTime[i + ] = time;
  49. }
  50.  
  51. for (int i = ; i < Q; ++i)
  52. {
  53. cin >> a;
  54. time = endTime[a];
  55. if (Sorry[a])
  56. printf("Sorry\n");
  57. else
  58. printf("%02d:%02d\n", + time / , time % );
  59. }
  60. return ;
  61. }
  1.  

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. iOS开发之SceneKit框架--SCNCamera.h

    1.SCNCamera简介 被称为照相机或者摄像机,可以附加到节点以提供显示场景的角度.其实就是用户视角和人的眼睛一样. 2.相关API简介 初始化 //懒加载 + (instancetype)cam ...

  2. Jenkins 自动部署

      一.安装插件[系统管理 → 插件管理 ] 为了通过SSH上传war包,我们需要安装Publish Over SSH 插件. 二.添加SSH 服务器[系统管理→系统设置] 参数说明: Name:ss ...

  3. CSS 属性1

    CSS列表属性 list-style:列表样式,取值:none.去掉项目符号或编号前面的各种符号. CSS边框属性:每个元素都可以加边框线  border-left:左边框线.   格式:border ...

  4. CentOS升级GDB

    需要先安装ncurses-devel和texinfo 如果不安装ncurses-devel,编译会出错 如果不安装texinfo或者版本太低,安装会出错 1.yum install -y ncurse ...

  5. pip install mysql-python报错1. Unable to find vcvarsall.bat 2 fatal error C1083: Cannot open include file: 'config-win.h': No such file or directory 3.error: command 'mt.exe' failed with exit statu

    最近在安装mysql -python 时报错折腾了半天,通过以下方法解决: 1. pip install mysql-python报错 Unable to find vcvarsall.bat (参考 ...

  6. 【学术篇】luogu1558&&poj2777 色板游戏

    题目の传送门: luogu:https://www.luogu.org/problem/show?pid=1558 poj:http://poj.org/problem?id=2777 题目大意:给有 ...

  7. Python全栈开发:web框架之tornado

    概述 Tornado 是 FriendFeed 使用的可扩展的非阻塞式 web 服务器及其相关工具的开源版本.这个 Web 框架看起来有些像web.py 或者 Google 的 webapp,不过为了 ...

  8. 2016.8.19上午初中部NOIP普及组比赛总结

    2016.8.19上午初中部NOIP普及组比赛总结 链接:https://jzoj.net/junior/#contest/home/1338 这次总结发得有点晚啊!我在这里解释一下, 因为浏览器的问 ...

  9. Python-函数基础(1)

    目录 函数定义 什么是函数? 定义函数三种形式 函数定义的特性 函数调用 函数返回值 return的特性: 函数的参数 有参函数 形参 位置形参 默认形参 实参 位置实参 关键字实参 可变长参数 形参 ...

  10. P++ 1.0.5

    #include<bits/stdc++.h> #define begin { #define end } #define while while( #define if if( #def ...