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. Controller 和 Action -1

    https://www.cnblogs.com/willick/p/3331521.html MVC 的每个请求都会提交到 Controller 处理.Controller 包含了对请求的逻辑处理,能 ...

  2. js中迭代方法

    基础遍历数组:            for()            for( in )             for(var i = 0;i<arr.length;i++){       ...

  3. 《深入理解Java虚拟机》读书笔记五

    第六章 类文件结构 1.无关性的基石 各种不同平台的虚拟机与所有平台都统一使用程序存储格式——字节码是构成平台无关的基石. 实现语言无关性的基础仍然是虚拟机和字节码存储格式,Java虚拟机不和包括Ja ...

  4. 阿里云安装Nginx+vue项目部署

    阿里云安装Nginx+vue项目部署 nginx安装包下载 http://nginx.org/en/download.html nginx安装 首先先安装PCRE pcre-devel 和Zlib,因 ...

  5. Django教程(2)

    from Django official document; Django 最初被设计用于具有快速开发需求的新闻类站点,目的是要实现简单快捷的网站开发. from 编写你的第一个 Django 应用, ...

  6. Error: Unexpected HTTP status 413 'Request Entity Too Large' on

    由于nginx的client_max_body_size设置过小,默认上传的文件小于所要上传的文件大小,把这个值调大就可以了,我这里在配置文件的server下更改如下: server { client ...

  7. 【Redis运行状态下切换RDB备份至AOF备份】

    "redis持久化方式有哪些?又有何区别? rdb:基于快照的持久化,速度更快,一般用作备份,主从复制也是依赖于rdb持久化功能. aof:以追加的方式记录redis操作日志的文件,可最大程 ...

  8. protobuf-net简单使用

    第一个测试的proto文件 syntax = "proto3"; package ProtoMsg; message Foo { ; int32 id = ; repeated b ...

  9. layui之弹出层关闭和刷新问题

    本篇文章是根据本人实际开发的例子来讲的,不一定适用各位看官的情况 描述: 主页面,弹出第一个弹框,第一个弹框中在弹出第二个弹框,如图: 1是主页面,2是子弹窗,3是孙弹窗 功能一:好了,第一个我要实现 ...

  10. 使用ResponseBodyAdvice统一包装响应返回String的时候出现java.lang.ClassCastException: com.xxx.dto.common.ResponseResult cannot be cast to java.lang.String

    代码如下: @Override public ResponseResult<Object> beforeBodyWrite(Object returnValue, MethodParame ...