PAT 1014 Waiting in Line (模拟)
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 (N**M+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.
- Customeri 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 customers 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, custome**r1 is served at windo**w1 while custome**r2 is served at windo**w2. Custome**r3 will wait in front of windo**w1 and custome**r4 will wait in front of windo**w2. Custome**r5 will wait behind the yellow line.
At 08:01, custome**r1 is done and custome**r5 enters the line in front of windo**w1 since that line seems shorter now. Custome**r2 will leave at 08:02, custome**r4 at 08:06, custome**r3 at 08:07, and finally custome**r5 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
思路
这题有个坑,如果有人在17:00之前到了窗口前,就必须完成此人的业务。即,17:00前开始服务的,就必须服务完。
我自己写了一组样例,方便大家调试自己的程序
INPUT
2 1 4 4
600 539 400 200
1 2 3 4
OUPUT
18:00
16:59
23:39
Sorry
代码
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <map>
#include <limits.h>
using namespace std;
int N, M, K, Q;
int t[1000 + 10]; //记录每个人咨询的时间
vector<int> myv[30]; // 模拟每个窗口前的人的标号 1-K
int pos = 1; //要插入到黄线内的人所在的位置
int num = 0; //结束的人数
int now = 0; // 当前的时间
bool cmp1(vector<int> a, vector<int> b){
return a.size() < b.size();
}
int main() {
cin >> N >> M >> K >> Q;
for(int i = 1; i <= K; i++){
cin >> t[i];
}
while(num < K){
// 进入黄线
vector<int> *min_t = min_element(myv + 1, myv + N + 1, cmp1);
while(pos <= K && (*min_t).size() != M){
int vi = min_t - myv;
myv[vi].push_back(pos);
//cout << vi << " " << pos << " " << now << endl;
min_t = min_element(myv + 1, myv + N + 1, cmp1);
pos++;
}
// 咨询业务
int flag = true;
while(flag){
if(num == K) break;
now++;
for(int i = 1; i <= N; i++){
if(myv[i].size()){
t[myv[i][0]]--;
if(t[myv[i][0]] == 0){
flag = false; //有人完成,需要插入人
t[myv[i][0]] = now;
num++;
myv[i].erase(myv[i].begin(), myv[i].begin() + 1);
//防止样例中,在540(17:00)刚刚结束时,再从第1变成第0
if(now == 540){
for(int z = 0; z < myv[i].size(); z++){
t[myv[i][z]] = INT_MAX;
}
}
}
}
}
if(now >= 540) break;
}
if(now >= 540){
//把每个队伍的第一个咨询结束,不是第一个的无法完成咨询业务(INT_MAX)
for(int i = 1; i <= N; i++){
for(int j = 0; j < myv[i].size(); j++){
if(j == 0 && t[myv[i][0]] != INT_MAX){
t[myv[i][0]] += now;
}
else{
t[myv[i][j]] = INT_MAX;
}
}
}
// 还未插入到黄线内部的人,也无法完成咨询业务
while(pos <= K){
t[pos++] = INT_MAX;
}
break;
}
}
for(int i = 1; i <= Q; i++){
int q = 0;
cin >> q;
if(t[q] == INT_MAX) cout << "Sorry" << endl;
else printf("%02d:%02d\n", 8 + t[q] / 60, t[q] % 60);
}
return 0;
}
PAT 1014 Waiting in Line (模拟)的更多相关文章
- PAT 1014 Waiting in Line (模拟)
1014. Waiting in Line (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Suppo ...
- PAT 1014. Waiting in Line
Suppose a bank has N windows open for service. There is a yellow line in front of the windows which ...
- 1014. Waiting in Line (模拟)
n个窗口就有n个队列,模拟这n个队列就可以了.需要注意的是,一个人在选择排队窗口的时候,他会选择排队人数最少的窗口,如果存在多个窗口排队的人数相同,那么他会选择编码最小的窗口. Note that s ...
- PAT 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 ...
- PAT甲级1014. Waiting in Line
PAT甲级1014. Waiting in Line 题意: 假设银行有N个窗口可以开放服务.窗前有一条黄线,将等候区分为两部分.客户要排队的规则是: 每个窗口前面的黄线内的空间足以包含与M个客户的一 ...
- 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 ...
- PAT A 1014. Waiting in Line (30)【队列模拟】
题目:https://www.patest.cn/contests/pat-a-practise/1014 思路: 直接模拟类的题. 线内的各个窗口各为一个队,线外的为一个,按时间模拟出队.入队. 注 ...
- PTA (Advanced Level) 1014 Waiting in Line
Waiting in Line Suppose a bank has N windows open for service. There is a yellow line in front of th ...
随机推荐
- D0 设计模式
单一职责 一个类只负责一个功能领域中的相应职责.,就一个类而言,应该只有一个引起它变化的原因. 单一职责原则告诉我们: 一个类不能太"累"! 在软件系统中, 一个类( 大到模块, ...
- normalization, standardization and regularization
Normalization Normalization refers to rescaling real valued numeric attributes into the range 0 and ...
- Openstack 简单梳理,(自用 慎点)
这个图里面的彩色方块,就是OpenStack最核心的组件. 推荐几个大咖,大家可以百度找他们的博客来看:陈沙克.何明桂.孔令贤,Cloudman.
- 如何在linux主机上运行/调试 arm/mips架构的binary
如何在linux主机上运行/调试 arm/mips架构的binary 原文链接M4x@10.0.0.55 本文中用于展示的binary分别来自Jarvis OJ上pwn的add,typo两道题 写这篇 ...
- 题解【洛谷P3884】[JLOI2009]二叉树问题
题面 题解 这道题目可以用很多方法解决,这里我使用的是树链剖分. 关于树链剖分,可以看一下我的树链剖分学习笔记. 大致思路是这样的: 第\(1\)次\(dfs\)记录出每个点的父亲.重儿子.深度.子树 ...
- Cut Ribbon
Polycarpus has a ribbon, its length is n. He wants to cut the ribbon in a way that fulfils the follo ...
- ASP学习笔记1
一.变量 1.1 声明变量 dim name name="Donald Duck" response.write("My name is: " & na ...
- MFC程序使用控制台打印
1.在OnCreate窗口创建方法中调用控制台窗口创建方法,创建的窗口是与MFC主窗口共存亡的 参考地址:https://blog.csdn.net/Yong_Qi2015/article/detai ...
- 基于语音识别、音文同步、图像OCR的字幕解决方案HtwMedia介绍
背景介绍 俗话说,“好记性不如乱笔头”,这充分说明了文字归档的重要性.如今随着微信.抖音等移动端app的使用越来越广,人们生产音.视频内容也越来越便捷.而相比语音和视频而言,文字具有易存档.易检索.易 ...
- 如何预测股票分析--先知(Prophet)
在上一篇中,我们探讨了自动ARIMA,但是好像表现的还是不够完善,接下来看看先知的力量! 先知(Prophet) 有许多时间序列技术可以用在股票预测数据集上,但是大多数技术在拟合模型之前需要大量的数据 ...