【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 ...
随机推荐
- 谷歌play上APK的下载
https://apkcombo.com/tw-hk/ 在google搜索 APK DOWNLAOD就有专门下载谷歌PLAY的APK的
- Angular NgModule(模块)
NgModule 模块是Angular种一个重要的点,因为Angular的基本构造块就是NgModule.NgModule 会把相关的代码收集到一些功能集中,形成功能单元.在使用Angular CL ...
- Cesium 基于MapBox底图加载3DTiles 模型
3DTiles 模型采用 CATIA V5 R22 --->3dxml --->GLB--->B3DM var extent = Cesium.Rectangle.fromDeg ...
- opencv:图像查找表 与 颜色表
LUT 使用 颜色查找表 example LUT applyColorMap // 读入制作好的lut.png Mat color = imread("D:/images/lut.png&q ...
- Genetic Algorithm 资源
算法源码: NeuralGenetic : https://github.com/ahmedfgad/NeuralGenetic evolving-simple-organisms : https:/ ...
- Docker容器CPU限制选项测试
目录 Docker容器CPU限制选项测试 参考 实验环境 --cpu-shares选项 测试 结论 --cpus选项 测试 结论 --cpuset-cpus选项 测试 结论 Docker容器CPU限制 ...
- 线段树——I hate it
[问题描述] 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少.这让很多学生很反感. 不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模 ...
- 用myeclipse快速搭建hibernate实现数据库访问
前言 hibernate使用的大致过程为引入jar包.配置主配置文件.配置映射文件.编写实体类.编写dao.但是每一步都需要知道的内容都相对不少,造成困难.如果使用myeclipse提供的支持将非常容 ...
- ubuntu mysql允许root用户远程登录
有两种方法: 一. 1.mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPT ...
- 九、Appium-python-UI自动化之通过text定位
1.通过xpath定位text xpath路径为://android.widget.EditText[@text='请输入包含街道的完整地址'] 2.通过AndroidUIAutomator # 这个 ...