PAT A 1014. Waiting in Line (30)【队列模拟】
题目:https://www.patest.cn/contests/pat-a-practise/1014
思路:
直接模拟类的题。
线内的各个窗口各为一个队,线外的为一个,按时间模拟出队、入队。
注意点:即使到关门时间,已经在服务中的客户(窗口第一个,接待时间早于关门时间)还是可以被服务的。其它的则不服务。
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std; int N;// (<=20, number of windows)
int M;// (<=10, the maximum capacity of each line inside the yellow line)
int K;// (<=1000, number of customers)
int Q;// (<=1000, number of customer queries)
#define INF 0x6FFFFFFF
typedef struct Customer
{
int process;
int leave;
}Customer; int main()
{
//input
scanf("%d%d%d%d",&N,&M,&K,&Q);
vector<Customer> cus(K);
for(int i = ; i < K; ++i)
{
scanf("%d", &cus[i].process);
cus[i].leave = INF;
}
//process
vector<queue<int>> winQueue(N);
vector<int> timeBase(N, );
int p;
for(p = ; p < N*M && p < K; ++p)
{
cus[p].leave = timeBase[p%N]+cus[p].process;
timeBase[p%N] = cus[p].leave;
winQueue[p%N].push(p);
}
//for somebody out of the normal queue
for(; p < K; ++p)
{
int mmin = INF;
int index = -;
for(int j = ; j < N; ++j)
{
int top = winQueue[j].front();
if(mmin > cus[top].leave)
{
index = j;
mmin = cus[top].leave;
}
}
//then pop
cus[p].leave = timeBase[index]+cus[p].process;
timeBase[index] = cus[p].leave;
winQueue[index].pop();
winQueue[index].push(p);
} //query
for(int i = ; i < Q; ++i)
{
int q;
scanf("%d",&q);
q--;
if(cus[q].leave-cus[q].process >= )
printf("Sorry\n");
else
printf("%02d:%02d\n", +cus[q].leave/, cus[q].leave%);
}
return ;
}
PAT A 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甲级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)-模拟,优先级队列
题意:n个窗口,每个窗口可以排m人.有k为顾客需要办理业务,给出了每个客户的办理业务时间.银行在8点开始服务,如果窗口都排满了,客户就得在黄线外等候.如果有一个窗口用户服务结束,黄线外的客户就进来一个 ...
- 【PAT甲级】1014 Waiting in Line (30 分)(队列维护)
题面: 输入四个正整数N,M,K,Q(N<=20,M<=10,K,Q<=1000),N为银行窗口数量,M为黄线内最大人数,K为需要服务的人数,Q为查询次数.输入K个正整数,分别代表每 ...
- 【PAT Advanced Level】1014. Waiting in Line (30)
简单模拟题,注意读懂题意就行 #include <iostream> #include <queue> using namespace std; #define CUSTOME ...
- PAT 1014 Waiting in Line (30分) 一个简单的思路
这题写了有一点时间,最开始想着优化一下时间,用优先队列去做,但是发现有锅,因为忽略了队的长度. 然后思考过后,觉得用时间线来模拟最好做,先把窗口前的队列填满,这样保证了队列的长度是统一的,这样的话如果 ...
- PAT (Advanced Level) 1014. Waiting in Line (30)
简单模拟题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm& ...
- 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 ...
随机推荐
- ubuntu下ssh使用proxy:corkscrew
1,安装corkscrew: sudo apt-get install corkscrew 2, 配置 vim ~/.ssh/config 写入如下: Host 10.1.*.* ProxyComma ...
- visual studio 2012 插件
下面来分享几个好用的插件:直接在Tools-Extensions and Updates-Online中搜索就可以安装了 (中文版位于:菜单-工具-扩展和更新-联机-Visual Studio库) 1 ...
- 解析sql语句中left_join、inner_join中的on与where的区别
以下是对在sql语句中left_join.inner_join中的on与where的区别进行了详细的分析介绍,需要的朋友可以参考下 table a(id, type):id type ---- ...
- php如何妩媚地生成执行的sql语句
会不会碰到这样一种情况呢?每次获取数据将数据和历史版本都有一定的差别,然而用ThinkPHP的addAll()函数,却会将已有的数据删掉再重新写入.这明显不是我们想要的.但自己写sql每次几十个字段也 ...
- web开发架构设计
2015-07-31 13:10:38 一, web服务器 .负载均衡 .不做对URL的rewrite逻辑判断, 全部转发到代码服务器的单一入口文件, 由代码去全权处理 二, 代码服务器(常跟web服 ...
- 小项目特供 贪吃蛇游戏(基于C语言)
C语言写贪吃蛇本来是打算去年暑假写的,结果因为ACM集训给耽搁了,因此借寒假的两天功夫写了这个贪吃蛇小项目,顺带把C语言重温了一次. 是发表博客的前一天开始写的,一共写了三个版本,第一天写了第一版,第 ...
- linux权限不够,sh不能用
linux下权限不够 chmod +x 脚本命令 ./脚本命令 即可... sh startup.sh启动tomcat,出现 This file is needed to run this prog ...
- IOS-ARC和垃圾回收机制
ARC是编译层面的东西,垃圾回收是程序运行以后的机制,两者不可混为一谈 苹果觉得垃圾回收这种严重影响电源使用效率的特性,同移动设备天生的实时性是相冲突的.但是在iOS 5当中苹果引入了自动内存管理机制 ...
- yii和wp做博客
第一步,安装yii和wp: 第二步,创建protected/components/ExceptionHandler.php文件 <?php class ExceptionHandler { pu ...
- October 1st 2016 Week 40th Saturday
Autumn, the year's last, loveliest smile. 秋,四季流转中的最后一抹,也是最美的那一抹微笑. I love autumn because it is the h ...