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 ...
随机推荐
- 前台改变asp button控件的值,后台取值没有改变的问题
前台: <asp:Button ID="btnEdit" Style="margin-left: 600px;" runat="server&q ...
- 如何测试本地是否能够正常访问云服务器的 Web 端口
在windows环境下打开DOS命令行 使用telnet命令.例如 telnet www.baidu.com 80 插播一条小知识:DOS下清屏的命令是cls. 首先很不幸,出现了['telnet' ...
- wl18xx wifi编译出现没有编译wlcore_sdio的情况
打开config.mk ........................................................................................ ...
- go mode
https://github.com/dominikh/go-mode.el http://blog.altoros.com/golang-part-1-main-concepts-and-proje ...
- 笨方法学python--安装和准备
1 下载并安装python http://python.org/download 下载python2.7. python2.7并不是python3.5的旧版本. python2现在应用较广,网上资料较 ...
- lepus bug
------------------------------------------------BUG fix-------------------------------------------- ...
- 【单源最短路】dijstra poj 1502
#include <cstdio> #include <iostream> #include <stdlib.h> #include <memory.h> ...
- apicloud教程2 (转载)
本帖最后由 中山赢友网络科技有限公司 于 2015-10-17 15:38 编辑 继<APICloud之小白图解教程系列(一):认识APICloud>之后的第二篇教程. 本篇教程有以下知识 ...
- oracle中to_date详细用法示例(oracle日期格式转换)
这篇文章主要介绍了oracle中to_date详细用法示例,包括期和字符转换函数用法.字符串和时间互转.求某天是星期几.两个日期间的天数.月份差等用法 TO_DATE格式(以时间:2007-11-02 ...
- Tree Restoring
Tree Restoring Time limit : 2sec / Memory limit : 256MB Score : 700 points Problem Statement Aoki lo ...