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. 初步自学Java小结

    本周学习Java使我印象最深刻的Java开发环境的安装与设置,通过下载Eclipse IDE for Java Developers初步搭建好了Java开发环境,之后利用视频了解了Java程序的类型及 ...

  2. day28 rsync服务端配置和客户端

    2. rsync守护进程部署方式 客户端---服务端 上厕所 4 rsync守护进程服务端配置: 第一个历程: 下载安装软件 rpm -qa|grep rsync yum install -y rsy ...

  3. CSS的长度单位

    对于css的长度单位真的有必要知道一下.那么css长度单位有哪些呢? 分成两大类: 1.绝对单位:不会因为其他元素的尺寸变化而变化.坚持自我. 2.相对单位:没有一个确定的值,而是由其他元素的尺寸影响 ...

  4. docker使用nginx实现ssl(https)反向代理其他容器应用

    安装nginx容器 搜索nginx镜像 docker search nginx 拉取最新版nginx docker pull nginx:latest 运行容器 docker run --name=n ...

  5. SpringBoot集成flowable碰见DMN不能初始化

    在idea创建了SpringBoot项目,集成flowable,运行的时候DMN引擎初始化失败,花了一天时间也没解决. 抱着试试的态度重新建立一个项目,加入同样的依赖,成功运行. 但把成功运行的项目配 ...

  6. js -- 高阶函数的使用

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. vue mvvm原理与简单实现 -- 上篇

    Object.defineProperty介绍-- let obj = {}; Object.defineProperty(obj,'school',{ configurable : true, // ...

  8. HTML连载61-焦点图、固定定位

    一.焦点图 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...

  9. Contos7下安装Redis

    第一步:在线下载Redis的安装包 cd /opt/ wget http://download.redis.io/releases/redis-5.0.2.tar.gz `ps:也可自行下载到本地,让 ...

  10. layui之laydate

    .点击年份马上关闭窗口并且赋值 html代码: <div class="layui-form-item"> <label class="layui-fo ...