题面:

输入四个正整数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 分)(队列维护)的更多相关文章

  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. PAT A 1014. Waiting in Line (30)【队列模拟】

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

  3. PAT甲级1014. Waiting in Line

    PAT甲级1014. Waiting in Line 题意: 假设银行有N个窗口可以开放服务.窗前有一条黄线,将等候区分为两部分.客户要排队的规则是: 每个窗口前面的黄线内的空间足以包含与M个客户的一 ...

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

  5. PAT 1014 Waiting in Line (30分) 一个简单的思路

    这题写了有一点时间,最开始想着优化一下时间,用优先队列去做,但是发现有锅,因为忽略了队的长度. 然后思考过后,觉得用时间线来模拟最好做,先把窗口前的队列填满,这样保证了队列的长度是统一的,这样的话如果 ...

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

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

  8. PAT甲级——1131 Subway Map (30 分)

    可以转到我的CSDN查看同样的文章https://blog.csdn.net/weixin_44385565/article/details/89003683 1131 Subway Map (30  ...

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

随机推荐

  1. SniperOJ-as fast as you can-Writeup

    SniperOJ-as fast as you can-Writeup 题目描述: 打开所给的题目地址 很容易可以看出这是一个简单的爬虫问题,爬去网页的信息并post,但在界面及网页源码中均没发现有价 ...

  2. Go 开发关键技术指南 | Go 面向失败编程 (内含超全知识大图)

    作者 | 杨成立(忘篱) 阿里巴巴高级技术专家 关注"阿里巴巴云原生"公众号,回复 Go 即可查看清晰知识大图! 导读:从问题本身出发,不局限于 Go 语言,探讨服务器中常常遇到的 ...

  3. tomcat服务器启动执行的两个方法

    第一 SetApplicationContext(需要继承ApplicationContextAware)重写 第二 ContextInitialize(需要继承servleContet)重写,(co ...

  4. Blockchain资源

    程序源码: https://github.com/HuangFJ/pyeth https://www.jianshu.com/p/b72b4eb259b8

  5. mysql 远程连接不上,bind-address参数配置要求,以及怎么去使得mysql能够允许远程的客户端访问

    刚安装了MySQL服务器,使用远程管理工具总是连接不上,因为知道mysql的默认端口是3306,于是使用telnet连接这个端口,(从这里可以学到telnet是可以这样用的) telnet 192.1 ...

  6. rf 环境

    googlechrome webdriver驱动下载 addrhttps://sites.google.com/a/chromium.org/chromedriver/downloads谷歌浏览器ap ...

  7. 如何把web项目部署到Linux云服务器(详细流程)

    转自: https://blog.csdn.net/M_Kerry/article/details/81664548

  8. 3_5 生成元(UVa1583)

    如果x加上x的各个数字之和得到y,就说x是y的生成元.给出n(1<=n<=100000),求最小生成元.无解输出0.例如,n=216,121,2005时的解分别为198,0,1979. 样 ...

  9. redis的使用1

    学Linux已经将近一个月了,Linux中讲到的redis的使用,到现在还不回具体的使用在php中,今天周末,于是想把redis的使用搞懂. 网上的资料不算多,但还需要硬着头皮学.其中找到这样一篇关于 ...

  10. ubuntu 18 python3.6更换国内源和pip3源

    1.更换国内源 查看Ubuntu18版本和codename(一定要注意codename对应) lsb_release -a No LSB modules are available. Distribu ...