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 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
题目分析:利用队列将可以入队的顾客入队 每次出队都选择那个出队后窗口时间最小的队列进行出队
注意 对于服务结束时间超出17点 但是开始时间小于17点的 也可以服务完成
 #include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
struct T
{
int Hour=;
int Minute=;
}T1[],T2[];
int Time[];
int Tag = ;
int main()
{
int N, M, K, Q;
cin >> N >> M >> K >> Q;
queue<int> Queue[];
for (int i = ; i <=K; i++)
cin >> Time[i];
for(int j=;j<M;j++)
for (int i = ; i < N; i++)
{
if(Tag<=K)
Queue[i].push(Tag++);
}
for (int j = ; j < K; j++)
{
int Min = ;
int Minp = -;
for (int i = ; i < N; i++)
{
if(!Queue[i].empty())
if ((T1[i].Hour * + T1[i].Minute + Time[Queue[i].front()]) < Min)
{
Min = T1[i].Hour * + T1[i].Minute + Time[Queue[i].front()];
Minp = i;
}
}
int num =Queue[Minp].front();
T1[Minp].Hour += (T1[Minp].Minute + Time[num]) / ;
T1[Minp].Minute = (T1[Minp].Minute + Time[num]) % ;
T2[num].Hour = T1[Minp].Hour;
T2[num].Minute = T1[Minp].Minute;
Queue[Minp].pop();
if (Tag <= K)
Queue[Minp].push(Tag++);
}
int q;
for (int i = ; i < Q; i++)
{
cin >> q;
if (T2[q].Hour < || (T2[q].Hour == && T2[q].Minute - Time[q] < ))
printf("%02d:%02d\n", T2[q].Hour, T2[q].Minute);
else
cout << "Sorry" << endl;
}
return ;
}
												

1014 Waiting in Line (30 分)的更多相关文章

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

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

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

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

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

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

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

  6. 1014 Waiting in Line (30)(30 分)

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

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

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

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

  9. 1014 Waiting in Line (30)(30 point(s))

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

随机推荐

  1. ZTMap室内地图定位平台设计方案

    1   系统总体设计 1.1  系统概述 基于臻图信息室内GIS地图平台和室内定位平台,通过室内定位设备的部署和信号采集,实现对室内人员和资产的实时定位.路线导航.区域管控告警.客流统计等相关功能. ...

  2. 爬取疫情数据,以django+pyecharts实现数据可视化web网页

    在家呆着也是呆着,不如做点什么消磨时间呗~ 试试用django+pyecharts实现疫情数据可视化web页面 这里要爬疫情数据 来自丁香园.搜狗及百度的疫情实时动态展示页 先看看劳动成果: 导航栏: ...

  3. JS中的call()方法和apply()方法用法总结(挺好 转载下)

    最近又遇到了JacvaScript中的call()方法和apply()方法,而在某些时候这两个方法还确实是十分重要的,那么就让我总结这两个方法的使用和区别吧. 1. 每个函数都包含两个非继承而来的方法 ...

  4. 由国产性能测试工具WEB压力测试仿真能力对比让我想到的

    软件的行业在中国已得到长足的发展,软件的性能测试在软件研发过程显得越来越重要.国产的性能工具在好多大公司都在提供云服务的有偿收费测试.如:阿里的PTS(Performance Testing Serv ...

  5. Java多线程并发07——锁在Java中的实现

    上一篇文章中,我们已经介绍过了各种锁,让各位对锁有了一定的了解.接下来将为各位介绍锁在Java中的实现.关注我的公众号「Java面典」了解更多 Java 相关知识点. 在 Java 中主要通过使用sy ...

  6. MySQL语句-关于表单的操作总结(新手)

    MySQl表的操作: 主键的添加: CREATE TABLE 表名(列名称 数据类型--id INT PRIMARY KEY AUTO_INCREMENT,列名称2 数据类型,············ ...

  7. Web过滤器和监听器

    1.过滤器 1.1什么是过滤器 Filter也称之为过滤器,它是Servlet技术中最激动人心的技术,WEB开发人员通过Filter技术,对web服务器管理的所有web资源:例如Jsp, Servle ...

  8. QQ小程序支付

    QQ小程序支付 Java后端 同学折腾QQ小程序的支付折腾了好几天,没有完成统一下单,因为我做过微信和支付宝支付,他就让我帮忙搞 我搞了好两三个小时,也没搞出来,最终我觉得问题在商户key那里,问了几 ...

  9. shell编程之变量赋值

    1.变量赋值: name=lbg 等号前后不能有空格 name="Lebron James" 变量值中有空格要用双引号 echo ${name} 用${}更保险 shopt -s ...

  10. Java与C语言的区别——含面向对象介绍

    很多初学编程的小伙伴或者想要学习编程的小白弄不清C语言和Java的区别.本文就针对萌新们尽量用通俗的语言来介绍一下我所理解的编程语言界的两大巨头. 为什么说是两巨头,介绍之前我们先看一下某度搜索出来的 ...