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 ...
随机推荐
- Android studio 使用心得(三)—从Eclipse迁移到Android studio
断断续续的也算是把eclipse上的代码成功迁移到android studio上来了,现在,我同事继续用eclipse,我用android studio,svn上还是之前eclipse的项目,迁移成功 ...
- 在ubuntu上使用Virtual-Box安装Mininet
使用Virtual-Box安装Mininet看上去简单,但其中也暗藏许多坑.我自己装了多次Mininet,但每次都有缺陷: mininet访问不了网络 用宿主机访问不了mininet虚拟机 最后,终于 ...
- 【大话QT之十三】系统软件自己主动部署实现方案
本篇文章是对[大话QT之十二]基于CTK Plugin Framework的插件版本号动态升级文章的补充,在上篇文章中我们阐述的重点是新版本号的插件已经下载到plugins文件夹后应该怎样更新本地正在 ...
- python 同时遍历多个变量
最近在用python的时候,用到遍历多个变量: import sys import math F58=11491939491.7 F=[11429229079.7,11374540753.7,1132 ...
- 1.2 Activity
Activity是个应用组件,它给用户提供了为了完成某些工作而可以进行交互操作的界面,例如,电话详情,打电 话,发邮件,或是浏览地图.每一个Activity都有一个窗口来绘制自已的用户界面.通常来说, ...
- yii2 RESTful API Develop
参考文档:http://www.yiiframework.com/doc-2.0/guide-rest.html 以 DB 中的 news 表为例创建该资源的 RESTful API,最终的测试通过工 ...
- 【每一个人都是梵高】A Neural Algorithm of Artistic Style
文章地址:A Neural Algorithm of Artistic Style 代码:https://github.com/jcjohnson/neural-style 这篇文章我认为可以起个浪漫 ...
- Servlet 容器对URI的处理
问题 请求到达server以后,server是怎样处理URI请求资源路径的,在与web.xml文件里的映射进行比对时的原则是什么. 方案 针对精确匹配.通配符匹配.后缀匹配三种模式改动web.xml文 ...
- 13 jsp include
假如您有一系列的页面, 每一个都拥有同样的导航栏, 联系信息和注脚, 好的解决方案是使用 jsp:include, 它可以将下面列出的任何内容插入到jsp的输出中: html 页面内容 纯文本文档的内 ...
- Vector、ArrayList、List使用深入剖析
线性表,链表,哈希表是常用的数据结构,在进行Java开发时,JDK已经为我们提供了一系列相应的类来实现基本的数据结构.这些类均在java.util包中.本文试图通过简单的描述,向读者阐述各个类的作用以 ...