PAT 1014 Waiting in Line (模拟)
1014. Waiting in Line (30)
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 (模拟)的更多相关文章
- 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 ...
- 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 ...
随机推荐
- unity, particle play once and destroy
粒子播放一次后销毁: //ref: http://answers.unity3d.com/questions/219609/auto-destroying-particle-system ...
- ubuntu下ssh设置firefox用的反向代理
mark一下: ssh -D 127.0.0.1:8080 -l root MyIp
- atitit.js javascript 调用c# java php后台语言api html5交互的原理与总结p97
atitit.js javascript 调用c# java php后台语言api html5交互的原理与总结p97 1. 实现html5化界面的要解决的策略1 1.1. Js交互1 1.2. 动态参 ...
- Vivado设计二:zynq的PS访问PL中的自带IP核(基于zybo)
1.建立工程 首先和Vivado设计一中一样,先建立工程(这部分就忽略了) 2.create block design 同样,Add IP 同样,也添加配置文件,这些都和设计一是一样的,没什么区别. ...
- Docker使用Dockerfile创建支持ssh服务自启动的容器镜像
原文链接:Docker使用Dockerfile创建支持ssh服务自启动的容器镜像 1. 首先创建一个Dockerfile文件.文件内容例如以下 # 选择一个已有的os镜像作为基础 FROM cento ...
- android studio - 导入工程报错[Plugin with id 'com.android.application' not found]
出错现象: 大概意思是找不到:com.android.application 插件,以上现象对于初学者来说会经常碰到,下面分析下产生的原因. 原因分析 首先来看看导入后的工程结构: 对于此工程结构,是 ...
- 蓝牙(CoreBluetooth)-中心设备(客户端)
蓝牙(CoreBluetooth)-中心设备(客户端) 蓝牙客户端-中心设备 主要内容 1. 创建`中央管理器` 2. 发现并且连接外设 3. 寻找连接上的外设数据 4. 发送读或写`特征值`的请求 ...
- 把以逗号分隔的字符串转换成list
/** * 把省的字符串转换成列表 * * @param province * @return */ private List<String> getProvinceList(String ...
- hdu 3652数位dp
/* 数位dp 题意:找到1-n之间包括13这个子串而且可以整除13的数 解:刚開始dp[N][N][2]这里的2用来记录是否为13表示当前位是否为13,我把上一位为1当前位为13和上一位部位1 这样 ...
- Python Excel 导入导出【转】
一.安装xlrd模块 到python官网下载http://pypi.python.org/pypi/xlrd模块安装,前提是已经安装了python 环境. 二.使用介绍 1.导入模块 import x ...