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 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.
- Customeri will take Ti 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, customer1 is served at window1 while 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 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 分)的更多相关文章
- 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 ...
- 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 ...
- PAT 1014 Waiting in Line (30分) 一个简单的思路
这题写了有一点时间,最开始想着优化一下时间,用优先队列去做,但是发现有锅,因为忽略了队的长度. 然后思考过后,觉得用时间线来模拟最好做,先把窗口前的队列填满,这样保证了队列的长度是统一的,这样的话如果 ...
- 【PAT甲级】1014 Waiting in Line (30 分)(队列维护)
题面: 输入四个正整数N,M,K,Q(N<=20,M<=10,K,Q<=1000),N为银行窗口数量,M为黄线内最大人数,K为需要服务的人数,Q为查询次数.输入K个正整数,分别代表每 ...
- 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 ...
- PAT A 1014. Waiting in Line (30)【队列模拟】
题目:https://www.patest.cn/contests/pat-a-practise/1014 思路: 直接模拟类的题. 线内的各个窗口各为一个队,线外的为一个,按时间模拟出队.入队. 注 ...
- 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 ...
- 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 ...
随机推荐
- web安全测试--环境搭建
本博客主要作为作者的学习笔记,请勿装载. 作为一个安全测试的入门选手,一切操作在虚拟机中进行是最保险的. 第一先下载自己喜欢的虚拟机,我的笔记本用的VirtualBox(下载地址:https://ww ...
- R语言实战(二) 创建数据集
2.1 数据集的概念 不同的行业对于数据集的行和列叫法不同.统计学家称它们为观测(observation)和变量(variable),数据库分析师则称其为记录(record)和字段(field),数据 ...
- 原来rollup这么简单之 rollup.generate + rollup.write篇
大家好,我是小雨小雨,致力于分享有趣的.实用的技术文章. 内容分为翻译和原创,如果有问题,欢迎随时评论或私信,希望和大家一起进步. 分享不易,希望能够得到大家的支持和关注. 计划 rollup系列打算 ...
- Android NDK JNI 入门笔记-day04-NDK实现Hash算法
* Android NDK JNI 入门笔记目录 * 开头 前面的学习,我们已经掌握了 NDK 开发的必备知识. 下一步就要多实践,通过创造问题并解决问题,来增加熟练度,提升经验. 日常开发中,经常会 ...
- 【MyBatis笔记】mapper文件的配置以及说明
<!doctype html>[MyBatis笔记]mapper文件的配置以及说明 figure:last-child { margin-bottom: 0.5rem; } #write ...
- Java序列化和反序列化-(新手)
实例: lx1: import java.io.*; public class xuliehua { public static void main(String[] args) throws Exc ...
- git提交更改都是一个作者
为什么提交到github的commit都是一个作者 参考链接 重要知识点讲解 问题如下所示 git是分布式去中心化的管理系统 ssh秘钥对生成.并把id_rsa.pub加入github.com中(这个 ...
- 写了个python脚本,循环执行某一个目录下的jmeter脚本————解决的问题,每次回归时,都得一个个拉取
import os import time #需要你改的就这3个参数 #path是放你jmx脚本的文件夹路径 path="D:\\桌面\\每次都是从共享上考最新的\\" #jtl_ ...
- python多重继承的属性和方法调用顺序问题和对迭代器的初步理解
推荐阅读:https://www.cnblogs.com/bigb/p/11650707.html 计算机学习的一个好办法就是自己将代码跑一遍,了解代码的运作顺序和原理(主要弄懂 函数作用,传入参数, ...
- 【转】linux中ifconfig 命令详解详解
1 概述 ifconfig工具不仅可以被用来简单地获取网络接口配置信息,还可以修改这些配置.用ifconfig命令配置的网卡信息,在网卡重启后机器重启后,配置就不存在.要想将上述的配置信息永远的存的电 ...