PAT (Advanced Level) 1014. Waiting in Line (30)
简单模拟题。
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<map>
#include<queue>
using namespace std; struct X
{
int st;
int len;
int en;
}p[];
queue<int>Q[];
int n,m,k,s; bool check()
{
for(int i=;i<=n;i++)
if(!Q[i].empty()) return ;
return ;
} int main()
{
scanf("%d%d%d%d",&n,&m,&k,&s);
for(int i=;i<=k;i++) scanf("%d",&p[i].len);
int pos;
for(pos=;pos<=min(k,n);pos++) { p[pos].st=; Q[pos].push(pos); }
for(;pos<=min(n*m,k);pos++)
{
int id=pos%n; if(id==) id=n;
Q[id].push(pos);
}
while()
{
if(check()==) break;
int Min=;
for(int i=;i<=n;i++)
{
if(Q[i].empty()) continue;
int id=Q[i].front();
Min=min(Min,p[id].st+p[id].len);
} for(int i=;i<=n;i++)
{
if(Q[i].empty()) continue;
int id=Q[i].front();
if(p[id].st+p[id].len==Min)
{
p[id].en=p[id].st+p[id].len;
Q[i].pop();
if(pos<=k) Q[i].push(pos++);
if(!Q[i].empty()) p[Q[i].front()].st=p[id].en;
}
}
}
for(int i=;i<=s;i++)
{
int id; scanf("%d",&id);
if(p[id].st/>=) printf("Sorry\n");
else printf("%02d:%02d\n",p[id].en/,p[id].en%);
}
return ;
}
PAT (Advanced Level) 1014. Waiting in Line (30)的更多相关文章
- 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 ...
- 【PAT甲级】1014 Waiting in Line (30 分)(队列维护)
题面: 输入四个正整数N,M,K,Q(N<=20,M<=10,K,Q<=1000),N为银行窗口数量,M为黄线内最大人数,K为需要服务的人数,Q为查询次数.输入K个正整数,分别代表每 ...
- 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 ...
- 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 Advanced Level】1014. Waiting in Line (30)
简单模拟题,注意读懂题意就行 #include <iostream> #include <queue> using namespace std; #define CUSTOME ...
- PAT A 1014. Waiting in Line (30)【队列模拟】
题目:https://www.patest.cn/contests/pat-a-practise/1014 思路: 直接模拟类的题. 线内的各个窗口各为一个队,线外的为一个,按时间模拟出队.入队. 注 ...
- PAT甲题题解-1014. Waiting in Line (30)-模拟,优先级队列
题意:n个窗口,每个窗口可以排m人.有k为顾客需要办理业务,给出了每个客户的办理业务时间.银行在8点开始服务,如果窗口都排满了,客户就得在黄线外等候.如果有一个窗口用户服务结束,黄线外的客户就进来一个 ...
- PAT 1014 Waiting in Line (30分) 一个简单的思路
这题写了有一点时间,最开始想着优化一下时间,用优先队列去做,但是发现有锅,因为忽略了队的长度. 然后思考过后,觉得用时间线来模拟最好做,先把窗口前的队列填满,这样保证了队列的长度是统一的,这样的话如果 ...
- 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 ...
随机推荐
- php根据时间显示刚刚,几分钟前,今天,昨天的实现代码
如果大家有更好的方案欢迎交流 function diffBetweenTwoDay($pastDay){ $timeC = time() - strtotime($pastDay); $dateC = ...
- linux expr命令参数及用法详解
expr用法 expr命令一般用于整数值,但也可用于字符串.一般格式为: #expr argument operator argument expr也是一个手工命令行计数器. #$expr 10 + ...
- perl中my和our的区别分析
来源: http://www.jb51.net/article/35528.htm perl中our的用法require 5.006当版本号小于 5.006 的时候,会返回失败,从而导致模块加载失败. ...
- PHP基本类型操作
//关键字对大小写不敏感echo ('hello world!<br>');ECho ('hello world<br>');eCho ('hello world<br& ...
- CodeForces 719B Anatoly and Cockroaches 思维锻炼题
题目大意:有一排蟑螂,只有r和b两种颜色,你可以交换任意两只蟑螂的位置,或涂改一个蟑螂的颜色,使其变成r和b交互排列的形式.问做少的操作次数. 题目思路:更改后的队列只有两种形式:长度为n以r开头:长 ...
- 1988: Sn 爆long long 的处理方法
题目描述 给你两个数 n, p(0 < n,p <= 10^15); a1 = 1; a2 = 1+2; a3 = 1+2+3; ... an = 1+2+3+...+n Sn ...
- php 大转盘抽奖
包在文件中 lottery.zip <!DOCTYPE HTML><html><head><meta charset="utf-8"> ...
- Singleton ——运行时全局唯一对象
Singleton 运行时全局唯一对象 Singleton模式只解决一个问题,如何做到运行时创建一个全局唯一的对象? 1:隐藏类的实例化操作,即将构造函数声明为private或protected.任何 ...
- dl以及dt,dd,以及table的tr,th,td最清楚分析
1,定义:<dl> <dt> <dd>是一组合标签,使用了dt dd最外层就必须使用dl包裹,此组合标签我们也又叫表格标签,与table表格类似组合标签,故名我们也 ...
- unit正交相机Size的计算公式
如:相机的大小为800*480,要使相机适应800*480像素的图,则 Size = 相机高/2/像素单位 = 480/2/100 = 2.4