题目: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. C#析构函数与垃圾回收

    析构函数基本语法 C# class Car { ~ Car() // destructor { // cleanup statements... } } 析构函数说明 不能在结构中定义析构函数.只能对 ...

  2. Fraction to Recurring Decimal

    Given two integers representing the numerator and denominator of a fraction, return the fraction in ...

  3. Shell 脚本 ,, 根据进程号退出 从而关机

    #!/bin/bash fun(){ ps -ef | grep "$1" | awk '{print $2 $8}' > /usr/file while read line ...

  4. ACM/ICPC 之 四道MST-Prim解法(POJ1258-POJ1751-POJ2349-POJ3026)

    四道MST,适合Prim解法,也可以作为MST练习题. 题意包括在代码中. POJ1258-Agri Net 水题 //Prim-没什么好说的 //接受一个邻接矩阵,求MST //Time:0Ms M ...

  5. php 获取IP

    <?php echo 'your ip is :'; if (@$_SERVER["HTTP_X_FORWARDED_FOR"]) $ip = $_SERVER[" ...

  6. hdu 1896.Stones 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1896 题目意思:给出 n 块石头的初始位置和能到达的距离.对于第奇数次遇到的石头才抛掷,偶数次的就忽略 ...

  7. SuperIndicator 专做轮播图库,没有之一,支持轮播图无限循环

    github地址:https://github.com/hejunlin2013/SuperIndicator SuperIndicator a superindicatorlibray for vi ...

  8. GridView如何合并同类项

    /// <summary>     /// 合并GridView中某列相同信息的行(单元格)     /// </summary>     /// <param name ...

  9. 核心动画基础动画(CABasicAnimation)关键帧动画

    1.在iOS中核心动画分为几类: 基础动画(CABasicAnimation) 关键帧动画(CAKeyframeAnimation) 动画组(CAAnimationGroup) 转场动画(CATran ...

  10. 【转】深入Windows内核——C++中的消息机制

    上节讲了消息的相关概念,本文将进一步聊聊C++中的消息机制. 从简单例子探析核心原理 在讲之前,我们先看一个简单例子:创建一个窗口和两个按钮,用来控制窗口的背景颜色.其效果 图1.效果图  Win32 ...