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 (模拟)的更多相关文章

  1. PAT 1014 Waiting in Line (模拟)

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

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

  3. 1014. Waiting in Line (模拟)

    n个窗口就有n个队列,模拟这n个队列就可以了.需要注意的是,一个人在选择排队窗口的时候,他会选择排队人数最少的窗口,如果存在多个窗口排队的人数相同,那么他会选择编码最小的窗口. Note that s ...

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

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

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

  6. PAT甲级1014. Waiting in Line

    PAT甲级1014. Waiting in Line 题意: 假设银行有N个窗口可以开放服务.窗前有一条黄线,将等候区分为两部分.客户要排队的规则是: 每个窗口前面的黄线内的空间足以包含与M个客户的一 ...

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

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

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

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

随机推荐

  1. MySQL | linux中数据库导出和导入

    一.数据库导出(深坑) 命令:mysqldump -u用户名 -p密码 要导出的数据库 > 导出之后的文件.sql mysqldump -uroot -p database_01 > da ...

  2. SPDK-nvmf与不同传输类型的公共接口

    SPDK-nvmf与不同传输类型的公共接口 不同类型的传输层到nvmf的公共命令请求接口 nvmf_fc_hwqp_handle_request() -->cmd_iu = buffer-> ...

  3. jQuery jqgrid

    1.写div <div class="ibox-content"> <div class="jqGrid_wrapper"> <! ...

  4. C++-new 的六种重载形式

    当写出这样的代码的时候, 实际上有两步操作: p = new P(); 1.分配内存, 2.然后在分配好的内存之上初始化类成员. 第二步是有构造函数完成的, 第一步就是new函数的工作. 全局的new ...

  5. 【NOIP2012普及组】质因数分解

    P1075 质因数分解 假期第一天就给一道入门难度的题写题解…… 这道题一开始就被我想复杂了:埃式筛,欧拉筛……然而开一个1e9的数组?不现实. 直到看到题解区的dalao用唯一分解定理: 算术基本定 ...

  6. Tomcat 端口配置,及原理详解

    1 tomcat 文件配置详细说明 tomcat服务器需配置三个端口才能启动,安装时默认启用了这三个端口,当要运行多个tomcat服务时需要修改这三个端口,不能相同.端口配置路径为tomcat\ co ...

  7. python 数据模型orm

    在__init__.py增加,因为默认的mysqldb不支持python3 import pymysql pymysql.install_as_MySQLdb() 创建表 from django.db ...

  8. flutter_html 和 WebView 解析html 和 build.gradle源码

    一.flutter_html 涉及的 api 接口: http://www.phonegap100.com/appapi.php?a=getPortalArticle&aid=20 二.Flu ...

  9. 每天进步一点点------Allegro手工建立电路板

    手工建立电路板步骤(以某个四层板为例): (1)file---new---board/board wizard来建立.brd电路板文件.设置名称和保存路径后,要设置绘图区域的大小,setup---dr ...

  10. 【做题笔记】洛谷P1955[NOI2015]程序自动分析

    第一道蓝题祭- 注意到本题中判断的是下标,即,并不是真的判断 \(i\) 是否等于 \(j\) 显然考虑并查集,把所有标记为"相等"的数放在一个集合里,然后最后扫一遍每个数,如果有 ...