题目: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)【队列模拟】的更多相关文章

  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甲级1014. Waiting in Line

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

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

  4. PAT甲题题解-1014. Waiting in Line (30)-模拟,优先级队列

    题意:n个窗口,每个窗口可以排m人.有k为顾客需要办理业务,给出了每个客户的办理业务时间.银行在8点开始服务,如果窗口都排满了,客户就得在黄线外等候.如果有一个窗口用户服务结束,黄线外的客户就进来一个 ...

  5. 【PAT甲级】1014 Waiting in Line (30 分)(队列维护)

    题面: 输入四个正整数N,M,K,Q(N<=20,M<=10,K,Q<=1000),N为银行窗口数量,M为黄线内最大人数,K为需要服务的人数,Q为查询次数.输入K个正整数,分别代表每 ...

  6. 【PAT Advanced Level】1014. Waiting in Line (30)

    简单模拟题,注意读懂题意就行 #include <iostream> #include <queue> using namespace std; #define CUSTOME ...

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

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

  8. PAT (Advanced Level) 1014. Waiting in Line (30)

    简单模拟题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm& ...

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

随机推荐

  1. 转帖: 使用脚本删除程序(免除在[控制面板]->[添加或删除程序]中的手工操作)

    1. 代码:VBS strComputer = "." '这个表示本地计算机 Set objWMIService = GetObject("winmgmts:" ...

  2. Word Search I & II

    Word Search I Given a 2D board and a word, find if the word exists in the grid. The word can be cons ...

  3. poj 2488

    http://poj.org/problem?id=2488 题意:就是让马把棋盘都走完,每一个点都要走到,出口就是a,b. #include <stdio.h> #include < ...

  4. struts2 初步总结

    1.Struts2的概述: 2.Struts2的入门: * 2.1下载struts2的zip包. * 2.2创建web工程. * 2.3配置... 3.Struts2的开发流程: * 3.1流程: * ...

  5. python程序打包成.exe----pyinstaller工具

    1. 环境 windows 2. 安装 准备文件:PyWin32 or pypiwin32 运行如下安装命令:  pip install pyinstaller==3.0 不要使用3.2版本,编译完成 ...

  6. ansible操作远程服务器报Error: ansible requires the stdlib json or simplejson module, neither was found!

    通过ansible执行远程命令时报如下异常: Error: ansible requires the stdlib json or simplejson module, neither was fou ...

  7. jenkins gitlab整合注意事项

    jenkins整合gitlab时,Source Code Management添加gitlab仓库路径无论怎么尝试都报如下两个异常: Failed to connect to repository : ...

  8. 用Java计算某个日期100天后的日期

    用Java计算日期时间,首先考虑到时间类,Java中提供的和时间日期相关的类里,有一个Calendar类,可以获取某个时间日期. 计算某个日期100天后的日期,思路如下: 1.先设定时间,例如2017 ...

  9. Java for LeetCode 209 Minimum Size Subarray Sum

    Given an array of n positive integers and a positive integer s, find the minimal length of a subarra ...

  10. 解析客户端IP

    <html><head><title>新浪IP解析接口的使用</title><metahttp-equiv=Content-Typecontent ...