【PAT甲级】1014 Waiting in Line (30 分)(队列维护)
题面:
输入四个正整数N,M,K,Q(N<=20,M<=10,K,Q<=1000),N为银行窗口数量,M为黄线内最大人数,K为需要服务的人数,Q为查询次数。输入K个正整数,分别代表每位顾客需要被服务的时间,Q次查询每次查询一位顾客被服务完离开银行的时间。如果他在五点以前(不包括五点)没有开始被服务,输出“Sorry”。
trick:
在五点以前(不包括五点)没有开始被服务,输出“Sorry”,而不是被服务完时间在五点以后(以题面为准)。
AAAAAccepted code:
#include<bits/stdc++.h>
using namespace std;
int a[];
queue<pair<int,int> >qu[];
int ans[];
int quy[];
int sum[];
int main(){
int n,m,k,q;
cin>>n>>m>>k>>q;
for(int i=;i<=k;++i)
cin>>a[i];
for(int i=;i<=q;++i)
cin>>quy[i];
for(int i=;i<=m;++i)
for(int j=;j<=n;++j)
if((i-)*n+j<=k)
qu[j].push({a[(i-)*n+j],(i-)*n+j});
int flag=m*n+;
while(){
int mn=1e9;
for(int i=;i<=n;++i)
if(!qu[i].empty()&&qu[i].front().first+sum[i]<mn)
mn=qu[i].front().first+sum[i];
if(mn==1e9)
break;
for(int i=;i<=n;++i)
if(!qu[i].empty()&&qu[i].front().first+sum[i]==mn){
if(sum[i]>=)
ans[qu[i].front().second]=-;
else{
sum[i]=mn;
ans[qu[i].front().second]=sum[i];
}
qu[i].pop();
if(flag<=k){
qu[i].push({a[flag],flag});
flag++;
}
}
}
for(int i=;i<=q;++i){
int hour=ans[quy[i]]/+;
int minute=ans[quy[i]]%;
if(ans[quy[i]]==-)
cout<<"Sorry";
else{
if(hour<)
cout<<""<<hour<<":";
else
cout<<hour<<":";
if(minute<)
cout<<""<<minute;
else
cout<<minute;
}
cout<<"\n";
}
return ;
}
【PAT甲级】1014 Waiting in Line (30 分)(队列维护)的更多相关文章
- 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 ...
- PAT A 1014. Waiting in Line (30)【队列模拟】
题目:https://www.patest.cn/contests/pat-a-practise/1014 思路: 直接模拟类的题. 线内的各个窗口各为一个队,线外的为一个,按时间模拟出队.入队. 注 ...
- PAT甲级1014. Waiting in Line
PAT甲级1014. Waiting in Line 题意: 假设银行有N个窗口可以开放服务.窗前有一条黄线,将等候区分为两部分.客户要排队的规则是: 每个窗口前面的黄线内的空间足以包含与M个客户的一 ...
- 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 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 ...
- 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 ...
- PAT甲级——1131 Subway Map (30 分)
可以转到我的CSDN查看同样的文章https://blog.csdn.net/weixin_44385565/article/details/89003683 1131 Subway Map (30 ...
- PAT 甲级 1076 Forwards on Weibo (30分)(bfs较简单)
1076 Forwards on Weibo (30分) Weibo is known as the Chinese version of Twitter. One user on Weibo m ...
随机推荐
- 解决:执行python脚本,提示错误:/usr/bin/python^M: 解释器错误: 没有那个文件或目录。
执行python脚本,提示错误: /usr/bin/python^M: 解释器错误: 没有那个文件或目录. 产生错误原因: \r字符被显示为^M,这时候只需要删除这个字符就可以了. Linux环境下: ...
- python进阶(十七)xml(下)
1.XML简介 xml用到的地方:tomcat配置文件 1) xml 指可扩展标记语言(Extensible Markup Language) 2) xml 被设计用于结构化.存储和传输数据 3) x ...
- SpringMVC注解@RequestMapping全面解析
@RequestMapping 可以出现在类级别上,也可以出现在方法上.如果出现在类级别上,那请求的 url 为 类级别上的@RequestMapping + 方法级别上的 @RequestMappi ...
- 开源协议:LGPL协议、OSGi协议
本文介绍开源的协议. LGPL 是 GNU Lesser General Public License (GNU 宽通用公共许可证)的缩写形式,旧称 GNU Library General Publi ...
- nginx解决WordPress 上传到服务器后页面404错误的方法
人啊,要说你傻了吧,真是啥事都能碰到: 因为换了nginx,把新做的上传到服务器配置好后,就主页和后台能打开,其他的所有页面,全是404,果真404和502是我最讨厌的数字啊,这让我很怀疑人生啊,怀疑 ...
- Codeforces Round #622 (Div. 2) C1. Skyscrapers (easy version)(简单版本暴力)
This is an easier version of the problem. In this version n≤1000n≤1000 The outskirts of the capital ...
- codeforces-Three Friends
Three Friends Three friends are going to meet each other. Initially, the first friend stays at the ...
- Operating systems Chapter 4
There are two processes to switch, when one run:io instruction, switch on other process. After ios, ...
- 10.Redis的RDB和AOF两种持久化机制的优劣势对比
1.RDB和AOF两种持久化机制的介绍 2.RDB持久化机制的优点3.RDB持久化机制的缺点4.AOF持久化机制的优点5.AOF持久化机制的缺点6.RDB和AOF到底该如何选择 我们已经知道对于一个企 ...
- C:C语言中表示进制数
#include <stdio.h> int main() { int a = 123; //十进制方式赋值 int b = 0123; //八进制方式赋值, 以数字0开头 int c = ...