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 ...
随机推荐
- lepus bug
------------------------------------------------BUG fix-------------------------------------------- ...
- zf-分页后台代码
java : public ResultPage getDeptList(int page, int pageRows) throws Exception { String hql="fro ...
- 【servlet】 第一个servlet
简单打印haha Helloyt.java package day01; import java.io.IOException; import javax.servlet.ServletConfig; ...
- Win32串口API
在工业控制中,工控机(一般都基于Windows平台)经常需要与智能仪表通过串口进行通信.串口通信方便易行,应用广泛. 一般情况下,工控机和各智能仪表通过RS485总线进行通信.RS485的通信方式是半 ...
- java socket解析和发送二进制报文工具(附java和C++转化问题)
解析: 首先是读取字节: /** * 读取输入流中指定字节的长度 * <p/> * 输入流 * * @param length 指定长度 * @return 指定长度的字节数组 */ pu ...
- Android OpenGL ES(六)创建实例应用OpenGLDemos程序框架 .
有了前面关于Android OpenGL ES的介绍,可以开始创建示例程序OpenGLDemos. 使用Eclipse 创建一个Android项目 Project Name: OpenGLDemos ...
- Spring Boot 系列教程4-JDBC
JDBC Java Data Base Connectivity,是一种用于执行SQL语句的Java API,可以为多种关系数据库提供统一访问,它由一组用Java语言编写的类和接口组成.不管是Hibe ...
- linux daemon
参考 鸟哥的私房菜 http://linux.vbird.org/linux_basic/0560daemons.php
- Android Camera(二)
上次已经写过SurfaceView显示Camera摄像了,代码可以运行,但是里面有问题,这次纠正过来,顺便实现变焦: 代码: public class CameravedioActivity exte ...
- Android自定义XML属性
<?xml version="1.0" encoding="utf-8"?> <resources> <declare-style ...