1014. Waiting in Line (30)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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 (NM+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.
  • Customer[i] 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 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

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

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 模拟题:
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <queue> using namespace std; int t[1005];
int l;
int start[1005];
int e[1005];
int n,m;
int k;
void fun(int time)
{
int hh=time/60;
int mm=time%60;
printf("%02d:%02d\n",8+hh,mm);
}
int main()
{
scanf("%d%d%d%d",&n,&m,&k,&l);
for(int i=1;i<=k;i++)
scanf("%d",&t[i]);
int cnt=1;
memset(e,-1,sizeof(e));
queue<int> q[1005];
for(int j=1;j<=m;j++)
{
for(int i=1;i<=n;i++)
{
if(cnt>k)
continue;
if(j==1)
start[cnt]=0;
q[i].push(cnt++);
}
}
for(int i=0;i<540;i++)
{
int num=1e5;
for(int j=1;j<=n;j++)
{
if(q[j].empty()) continue;
int x=q[j].front();
if(start[x]+t[x]==i)
{
e[x]=i;
q[j].pop();
if(!q[j].empty())
{
int x=q[j].front();
start[x]=i;
}
}
}
if(cnt>k)
continue;
for(int j=1;j<=n;j++)
{
if(q[j].size()<m)
{
if(cnt>k)
continue;
if(q[j].empty())
start[cnt]=i;
q[j].push(cnt++);
}
}
}
for(int i=1;i<=n;i++)
{
if(!q[i].empty())
{
int x=q[i].front();
if(start[x]<540)
e[x]=start[x]+t[x];
}
}
int pos;
for(int i=1;i<=l;i++)
{
scanf("%d",&pos);
if(e[pos]==-1)
printf("Sorry\n");
else
fun(e[pos]);
}
return 0; }

PAT 1014 Waiting in Line (模拟)的更多相关文章

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

  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. Mac /Ubuntu/Windows 下安装nodejs

    Mac If you're using the excellent homebrew package manager, you can install node with one command: b ...

  2. jqgrid 加按钮列

    1.在jqgrid表格中增加列,内容是图标,定义图标单击事件,可以操作这一行的数据,如下图 2.前台代码 <div id="grid_List"> <table ...

  3. 自定义asp.net mvc Filter 过滤器

    1新建一个mvc项目:如图 2.主要创建下面一些类文件 1.utility目录 放置自定义的过滤器 using System; using System.Collections.Generic; us ...

  4. simpleRNN

    simpleRNN 训练集为<爱丽丝梦境>英文版txt文档,目标:根据随机给出的10个字符,生成可能的后100个字符 词向量空间生产 In [4]: INPUT_FILE = " ...

  5. Spring Aop基础总结

    什么是AOP: Aop技术是Spring核心特性之中的一个,定义一个切面.切面上包括一些附加的业务逻辑代码.在程序运行的过程中找到一个切点,把切面放置在此处,程序运行到此处时候会运行切面上的代码.这就 ...

  6. UVA812-Trade on Verweggistan(暴力)

    题目链接 题意:商人要去买pruls这样的东西.然后它的价值是一个序列,买的时候要严格从头到尾取,比方你要买第5个,那么前4个也要一起买下来,求商人能获得的最大的利润. 思路:最大利润肯定就是每一个序 ...

  7. hadoop节点挂死的一次分析报表。

    hadoop的一个节点unused了.然后重启启动hadoop的服务,仍有有一个hadoop的节点起不来.多次重启hadoop和杀进程之后,发现hadoop的master和slave节点上的状态在切换 ...

  8. linux学习笔记18---目录结构

    对于每一个Linux学习者来说,了解Linux文件系统的目录结构,是学好Linux的至关重要的一步.,深入了解linux文件目录结构的标准和每个目录的详细功能,对于我们用好linux系统至关重要,下面 ...

  9. 使用SWT技术的跨平台移动应用开发库Tabris

    1. http://developer.eclipsesource.com/tabris/ 2. 多平台.原生程序级别的性能 3. 开源/教育性的项目免费,意思就是商业项目收费 4. 目标,让懂jav ...

  10. php 路由实现

    因为有小的业务逻辑比较复杂,orm用起来很麻烦,但是多入口又不好控制,每个页面都去包含,多了就迷了,所以就只写了个路由,加了个防注入 封装增删改查好无聊,直接封装业务逻辑,为业务而开发,业务逻辑里是面 ...