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 ...
随机推荐
- shell:crontab
crontab */1 * * * * (cd /home/q/system/project; /usr/bin/lockf -t 0 /tmp/discuz_bbs_audit.lock /usr/ ...
- xcode单步调试快捷键
xcode单步调试快捷键f6,但是磨人f6是用来调节键盘亮度的,在系统偏好,键盘设置里面,做如下设置就可以了.
- MySQL的索引创建、删除
1_1.添加PRIMARY KEY(主键索引) mysql>ALTER TABLE `table_name` ADD PRIMARY KEY ( `column` ) 1_2.添加UNIQUE ...
- 在调试安卓系统的时候需要这个 ”adb disable-verity“
在调试设备的时候.想要对文件进行读写 于是使用adb remount 出现提示. 请使用 ”adb disable-verity“ 于是使用adb disable-verity 的命令. 得到如下 ...
- 学习笔记:GLSL Core Tutorial – Vertex Shader(内置变量说明)
1.每个Vertex Shader都有用户定义的输入属性,例如:位置,法线向量和纹理坐标等.Vertex Shaders也接收一致变量(uniform variables). uniform vari ...
- 将页面内容转为Excel下载
使用:method1(table); 说明:参数table为table元素的ID; var idTmr; function getExplorer() { var explorer = window. ...
- 查找mysql数据库中所有包含特定名字的字段所在的表
整个数据库查找 placement 字段: select * from INFORMATION_SCHEMA.columns where COLUMN_NAME Like '%placement%'; ...
- HDU 1698 <线段树,区间set>
题目连接 题意: 一条长为N的铜链子,每个结点的价值为1.有两种修改,l,r,z; z=2:表示把[l,r]区间内链子改为银质,价值为2. z=3:表示把[l,r]区间内链子改为金质,价值为3. 思路 ...
- ubuntu 常用命令记录
1.# 表示权限用户(如:root),$ 表示普通用户 开机提示:Login:输入用户名 password:输入口令 用户是系统注册用户成功登陆后,可以进入相应的用户环境. 退出当前shel ...
- 解决IOS safari在input focus弹出输入法时不支持position fixed的问题
该文章为转载 我们在做移动web应用的时候,常常习惯于使用position:fixed把一个input框作为提问或者搜索框固定在页面底部.但在IOS的safari和webview中,对position ...