这题写了有一点时间,最开始想着优化一下时间,用优先队列去做,但是发现有锅,因为忽略了队的长度。

然后思考过后,觉得用时间线来模拟最好做,先把窗口前的队列填满,这样保证了队列的长度是统一的,这样的话如果到某个时间,队首的人已经服务完了,这样这个队列的长度就减少一,这就变成了所有队列中长度最短的队列,所以直接向这个队列里面添加一个人就可以了。

按照从小到大轮询窗口的话,这样正好符合题中的要求,就是队列长度相同短,先选窗口序号小的窗口。如果按照这种策略,少一个就补一个的策略,队列长度会一直保持相等。

#include <bits/stdc++.h>
using namespace std;
const int maxn=1010; int ans[maxn],a[maxn],N,M,K,Q,t[maxn];
queue<int> q[22];
int pret[22]; void print(int t)
{
if (t==-1) {
printf("Sorry\n");
return;
} t+=480;
int hh=t/60,mm=t%60;
// printf("%d %d ",hh,mm);
if (hh>17) {
printf("Sorry\n");
}
else {
printf("%02d:%02d\n",hh,mm);
}
} int main()
{
// freopen("in.txt","r",stdin);
scanf("%d%d%d%d",&N,&M,&K,&Q);
for (int i=1;i<=K;i++) {
scanf("%d",&t[i]);
}
for (int i=1;i<=Q;i++) {
scanf("%d",&a[i]);
}
int c=1;
for (int i=1;i<=M;i++) {
for (int j=1;j<=N;j++) {
q[j].push(c++);
if (c>K) {
break;
}
}
}
memset(ans,-1,sizeof(ans));
for (int i=0;i<=540;i++) {
if (c>K) break;
for (int j=1;j<=N;j++) {
int p=q[j].front();
int tt=t[p];
if (i-pret[j]==tt) {
ans[p]=i;
q[j].pop();
q[j].push(c++);
pret[j]=i;
if (c>K) {
goto outloop;
}
}
}
}
outloop:
for (int j=1;j<=N;j++) {
while (!q[j].empty()) {
if (pret[j]>=540) {
break;
}
int p=q[j].front();
ans[p]=pret[j]+t[p];
pret[j]+=t[p];
q[j].pop(); }
}
for (int i=1;i<=Q;i++) {
print(ans[a[i]]);
} return 0;
}

PAT 1014 Waiting in Line (30分) 一个简单的思路的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 【PAT甲级】1014 Waiting in Line (30 分)(队列维护)

    题面: 输入四个正整数N,M,K,Q(N<=20,M<=10,K,Q<=1000),N为银行窗口数量,M为黄线内最大人数,K为需要服务的人数,Q为查询次数.输入K个正整数,分别代表每 ...

  4. PTA 1014 Waiting in Line (30分) 解题思路及满分代码

    题目 Suppose a bank has N windows open for service. There is a yellow line in front of the windows whi ...

  5. 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 ...

  6. PAT 1014 Waiting in Line (模拟)

    1014. Waiting in Line (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Suppo ...

  7. PAT 甲级 1080 Graduate Admission (30 分) (简单,结构体排序模拟)

    1080 Graduate Admission (30 分)   It is said that in 2011, there are about 100 graduate schools ready ...

  8. PAT A 1014. Waiting in Line (30)【队列模拟】

    题目:https://www.patest.cn/contests/pat-a-practise/1014 思路: 直接模拟类的题. 线内的各个窗口各为一个队,线外的为一个,按时间模拟出队.入队. 注 ...

  9. 1014 Waiting in Line (30)(30 分)

    Suppose a bank has N windows open for service. There is a yellow line in front of the windows which ...

随机推荐

  1. LaTeX 文字带边框

    1.使用framed宏包 \usepackage{framed} 可以使用verb|...|和verbatim环境而不使用cprotect宏包的cprotect命令 \begin{framed} \v ...

  2. 页面回显与URL模板映射

    一.页面回显 对于需要返回界面的数据,可以将后台封装好的数据回显至原始jsp界面中. 举个例子: User.java package com.zk.data; public class User { ...

  3. 2019牛客多校第五场 G subsequence 1 dp+组合数学

    subsequence 1 题意 给出两个数字串s,t,求s的子序列中在数值上大于t串的数量 分析 数字大于另一个数字,要么位数多,要么位数相同,字典序大,位数多可以很方便地用组合数学来解决,所以只剩 ...

  4. PP: Pattern Trails: visual analysis of pattern transitions in subspaces

    Problem: 1. We can't find patterns in full attribute space, and patterns may only be found in smalle ...

  5. TD - 系统异常 - 登录不上

    问题描述:登录之后,页面停留在登录页面,没有任何错误提示 解决办法:重新安装插件

  6. 在多租户(容器)数据库中如何创建PDB:方法6 DBCA本地克隆PDB

    基于版本:19c (12.2.0.3) AskScuti 创建方法:DBCA静默本地克隆PDB.根据 CDB1 中的 PDB1 克隆出 CDB1 中的 PDB_CLONE 对应路径:Creating ...

  7. How to Create an OCM Response file to Apply a Patch in Silent Mode - opatch silent

    Windows Server 2019 打补丁时缺少Oracle Configuration Manager(OCM) 响应文件处理方式. 适用: Oracle Universal Installer ...

  8. cURL是什么

    原文链接:https://www.leiue.com/what-is-curl cURL 是一个利用 URL 语法在命令行下工作的文件传输工具,1997 年首次发行.它支持文件上传和下载,所以是综合传 ...

  9. python3练习100题——020

    原题链接:http://www.runoob.com/python/python-exercise-example20.html 题目:一球从100米高度自由落下,每次落地后反跳回原高度的一半:再落下 ...

  10. SQL中 select count(1) count中的1 到底是什么意思呢?和count(*)的区别

    count(1),其实就是计算一共有多少符合条件的行. 1并不是表示第一个字段,而是表示一个固定值.其实就可以想成表中有这么一个字段,这个字段就是固定值1,count(1),就是计算一共有多少个1.同 ...