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 ...
随机推荐
- Response.Redirect()、Server.Execute和Server.Transfer的区别
1.Response.Redirect(): Response.Redirect方法导致浏览器链接到一个指定的URL. 当Response.Redirect()方法被调用时,它会创建一个应答,应答头中 ...
- 流程图制作在云上 https://www.processon.com/
流程图制作在云上 : https://www.processon.com/
- fastReport 运行时设计报表 (mtm)
设计报表 通过“TfrxReport.DesignReport”方法调用报表设计器.你必须在你的项目中包含报表设计器 (必要条件是:要么使用“TfrxDesigner”组件,要么增加“frxDesgn ...
- java基础学习05(面向对象基础01--类实例分析)
面向对象基础01(类实例分析) 实现的目标 1.如何分析一个类(类的基本分析思路) 分析的思路 1.根据要求写出类所包含的属性2.所有的属性都必须进行封装(private)3.封装之后的属性通过set ...
- C#字符串的四舍五入
Round(Decimal) Round(Double) Round(Decimal, Int32) Round(Decimal, MidpointRounding) Round(Double, In ...
- [Android Pro] AIDL进程间传递自定义类型参数
1.创建.aidl 文件 AIDL 语法简单,用来声明接口,其中的方法接收参数和返回值,但是参数和返回值的类型是有约束的,且有些类型是需要 import,另外一些则无需这样做. AIDL 支持的数据类 ...
- 模拟赛1103d1
取模(mod) [题目描述] 有一个整数a和n个整数b_1, -, b_n.在这些数中选出若干个数并重新排列,得到c_1,-, c_r.我们想保证a mod c_1 mod c_2 mod - mod ...
- 体系结构设计MVC
体系结构设计MVC(viso图)GIT: https://coding.net/u/lklzjh/p/travel/git/blob/master/%E4%BD%93%E7%B3%BB%E7%BB%9 ...
- jquery学习笔记----jquery相关的文档
http://tool.oschina.net/apidocs/apidoc?api=jquery http://www.w3school.com.cn/jquery/jquery_ref_event ...
- HTML5 – 1.基础
新网页结构 1.<header> 定义了文档的头部区域 2.<nav>标签定义导航链接的部分. 3.<article>定义页面独立的内容区域. 4.<sect ...