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 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 (≤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 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

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <queue>
using namespace std;
const int maxn = ;
int n, m, k, q, now = ;
int t[maxn] = { };
int done[maxn] = { };
int pre[maxn] = { };
struct people {
int id;
int time;
int time_const;
};
queue<people*> que[];
int main() {
scanf("%d %d %d %d", &n, &m, &k, &q);
if (n == || m == ) {
for (int i = ; i < q; i++) {
printf("Sorry\n");
}
}
for (int i = ; i <= k; i++) {
int time;
scanf("%d", &time);
people *p = new people;
p->id = i;
p->time = time;
p->time_const = time;
if(i<=n*m)que[(i-)%n].push(p);
else {
int first = , first_j = ;
for (int j = ; j < n; j++) {
if (que[j].front()->time < first) {
first = que[j].front()->time;
first_j = j;
}
} for (int j = ; j < n; j++) {
que[j].front()->time -= first;
}
people* tmp_p = que[first_j].front();
que[first_j].pop();
now += first;
done[tmp_p->id] = now;
que[first_j].push(p);
pre[tmp_p->id] = now - tmp_p->time_const;
delete(tmp_p);
}
}
for (int i = ; i < n; i++) {
int tmp_now = now;
while (!que[i].empty()) {
people* tmp_p = que[i].front(); que[i].pop();
tmp_now += tmp_p->time;
pre[tmp_p->id] = tmp_now - tmp_p->time_const;
done[tmp_p->id] = tmp_now;
delete(tmp_p);
}
}
for (int i = ; i < q; i++) {
int j;
scanf("%d", &j);
//printf("%d %d\n", pre[j], done[j]);
if (pre[j]>=)printf("Sorry\n");
else {
printf("%02d:%02d\n", +done[j]/,done[j]%);
}
}
system("pause");
}

注意点:考察队列知识,相对比较简单,有一个坑就是结束时间在17点后但开始时间17点前还是要输出时间的,一开始没注意就错了三个测试点。

PAT A1014 Waiting in Line (30 分)——队列的更多相关文章

  1. PAT 1014 Waiting in Line (30分) 一个简单的思路

    这题写了有一点时间,最开始想着优化一下时间,用优先队列去做,但是发现有锅,因为忽略了队的长度. 然后思考过后,觉得用时间线来模拟最好做,先把窗口前的队列填满,这样保证了队列的长度是统一的,这样的话如果 ...

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

  4. 【PAT甲级】1014 Waiting in Line (30 分)(队列维护)

    题面: 输入四个正整数N,M,K,Q(N<=20,M<=10,K,Q<=1000),N为银行窗口数量,M为黄线内最大人数,K为需要服务的人数,Q为查询次数.输入K个正整数,分别代表每 ...

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

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

  6. PAT-1014 Waiting in Line (30 分) 优先队列

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

  7. 1014 Waiting in Line (30 分)

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

  8. PTA 1014 Waiting in Line (30分) 解题思路及满分代码

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

  9. PAT 1014 Waiting in Line (模拟)

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

随机推荐

  1. quartz部署出现找不到表的情况,错误提示: Table 'heart_beat.QRTZ_LOCKS' doesn't exist

    描述一下,本地可以,部署到Linux就不行,Linux上的数据库是本地直接拷贝上去的,项目环境是Spring Boot2.1.Shiro.MyBatis.Redis.swagger.Bootstrap ...

  2. 透明度 rgba 和 opacity 的区别

    rgba: 使用方式:rgba(255, 255, 255, .5) 最后一个参数表示透明度取值范围 0 ~1    只作用于元素的颜色或其背景色. opacity :  使用方式:opacity : ...

  3. react组件中的constructor和super小知识

    react组件中的constructor和super小知识 1.react中用class申明的类一些小知识 如上图:类Child是通过class关键字申明,并且继承于类React. A.Child的类 ...

  4. HTML5是什么,以及优点和缺点

    HTML5是超文本标记语言HTML的第五次重大修改 HTML 5 的第一份正式草案已于2008年1月22日公布 2013年5月6日, HTML 5.1正式草案公布 HTML5的优缺点是什么?作为HTM ...

  5. 遇到了ImportError: libmysqlclient_r.so.16: cannot open shared object file: No such file or directory

    解决方法如下: 1. 通过命令查找libmysqlclient_r.so.16 在什么地方,一般是在/usr/lib64/mysql/下面 2. 做一个链接到/usr/lib64 下: ln -s / ...

  6. beego+vue父子组件通信(父子页面传值、父子组件传值、父子路由传值)

    场景:有head和foot,为父组件 侧栏tree为子组件 点击tree,右侧孙组件根据点击tree的id,来更改表格内容. 首先是父子(本例中是子组件与孙组件)通信,目前是父传到子,暂时还没有子传到 ...

  7. SQL Server 全文索引介绍(转载)

    概述 全文引擎使用全文索引中的信息来编译可快速搜索表中的特定词或词组的全文查询.全文索引将有关重要的词及其位置的信息存储在数据库表的一列或多列中.全文索引是一种特殊类型的基于标记的功能性索引,它是由 ...

  8. windows系统安装python3.6.3和python3.7.0

    一.装备好从官网下载的python软件包(3.6.3和3.7.0) 二.先安装python3.6.3 1.运行python3.6.3文件 2.选择默认 3.下一步,等待安装 4.检查是否安装成功 ,安 ...

  9. Centos7.2中安装pip

    CentOS安装python-pip 在使用Python时,需要导入一些第三方工具包,一般情况下,鼓励使用pip来安装管理这些第三方的包, 这里我们来看一下如何在CentOS 7.2上安装Python ...

  10. 手机上的m3u8视频(缓存)怎么转成MP4?

    一.下载M3u8合并APK,自定义扫描手机中的m3u8文件目录.选择导出的目录,可以多个同时进行m3u8的合并任务. 合并后的文件可以完整播放,但是视频时间只有前十来秒,进度无法拖动. 二.将合并好的 ...