Suppose a bank has K windows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. All the customers have to wait in line behind the yellow line, until it is his/her turn to be served and there is a window available. It is assumed that no window can be occupied by a single customer for more than 1 hour.

Now given the arriving time T and the processing time P of each customer, you are supposed to tell the average waiting time of all the customers.

Input Specification:

Each input file contains one test case. For each case, the first line contains 2 numbers: N (≤10​4​​) - the total number of customers, and K (≤100) - the number of windows. Then N lines follow, each contains 2 times: HH:MM:SS - the arriving time, and P - the processing time in minutes of a customer. Here HH is in the range [00, 23], MM and SS are both in [00, 59]. It is assumed that no two customers arrives at the same time.

Notice that the bank opens from 08:00 to 17:00. Anyone arrives early will have to wait in line till 08:00, and anyone comes too late (at or after 17:00:01) will not be served nor counted into the average.

Output Specification:

For each test case, print in one line the average waiting time of all the customers, in minutes and accurate up to 1 decimal place.

Sample Input:

7 3
07:55:00 16
17:00:01 2
07:59:59 15
08:01:00 60
08:00:00 30
08:00:02 2
08:03:00 10

Sample Output:

8.2

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <queue>
#include <string>
#include <set>
#include <map>
using namespace std;
const int maxn = ;
int n,k;
queue<int> q[maxn];
struct person {
int arr;
int arr_const;
int start;
int pro;
int wait=;
};
bool cmp(person p1, person p2) {
return p1.arr < p2.arr;
}
vector<person> v;
int h, m, s, process;
int main(){
int count = ,time = ;
cin >> n >> k;
for (int i = ; i < n; i++) {
person p;
scanf("%d:%d:%d %d", &h, &m, &s, &process);
getchar();
time = * h + * m + s;
p.arr = time;
p.start = time;
p.arr_const = time;
p.pro = process*;
p.wait = ;
if (time > * )continue;
v.push_back(p);
count++;
}
sort(v.begin(), v.end(), cmp);
int now = *;
for (int i = ; i < count; i++) {
if (v[i].arr < now) {
v[i].wait = now - v[i].arr;
v[i].start = now;
v[i].arr = now;
}
}
int now_time = * ;
int fast_k = ;
for (int i = ; i < count - k; i++) {
int fast = ;
for (int j = ; j < i+k; j++) {
if (v[j].start + v[j].pro < fast) {
fast = v[j].start + v[j].pro;
fast_k = j;
}
}
v[fast_k].start = ;
now_time = fast;
if (now_time > v[i + k].arr) {
v[i + k].wait += now_time - v[i + k].arr;
v[i + k].start = now_time;
}
} float mean = ;
for (int i = ; i < count; i++) {
mean += v[i].wait;
}
if (count == )printf("0.0");
else {
mean /= count;
printf("%.1f", mean/);
}
system("pause");
return ;
}

注意点:又是一道逻辑挺简单的题,还是花了1个多小时才ac,前半部分思路是没问题的,后面窗口等待走歪了,一直在顾客上做文章,其实只要把每个窗口的开始服务时间更新,到的比窗口服务时间早的就等待,否则直接开始不用等。

PAT A1017 Queueing at Bank (25 分)——队列的更多相关文章

  1. PAT 甲级 1017 Queueing at Bank (25 分)(模拟题,有点思维小技巧,第二次做才理清思路)

    1017 Queueing at Bank (25 分)   Suppose a bank has K windows open for service. There is a yellow line ...

  2. 【PAT甲级】1017 Queueing at Bank (25 分)

    题意: 输入两个正整数N,K(N<=10000,k<=100)分别表示用户的数量以及银行柜台的数量,接下来N行输入一个字符串(格式为HH:MM:SS)和一个正整数,分别表示一位用户到达银行 ...

  3. PAT 1017 Queueing at Bank (25) (坑题)

    Suppose a bank has K windows open for service. There is a yellow line in front of the windows which ...

  4. [PAT] A1017 Queueing at Bank

    [思路] 1:将所有满足条件的(到来时间点在17点之前的)客户放入结构体中,结构体的长度就是需要服务的客户的个数.结构体按照到达时间排序. 2:wend数组表示某个窗口的结束时间,一开始所有窗口的值都 ...

  5. 1017 Queueing at Bank (25 分)

    Suppose a bank has K windows open for service. There is a yellow line in front of the windows which ...

  6. PAT 1017 Queueing at Bank[一般]

    1017 Queueing at Bank (25)(25 分)提问 Suppose a bank has K windows open for service. There is a yellow ...

  7. PAT 1017 Queueing at Bank (模拟)

    1017. Queueing at Bank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Supp ...

  8. pat1017. Queueing at Bank (25)

    1017. Queueing at Bank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Supp ...

  9. PAT 甲级 1051 Pop Sequence (25 分)(模拟栈,较简单)

    1051 Pop Sequence (25 分)   Given a stack which can keep M numbers at most. Push N numbers in the ord ...

随机推荐

  1. canvas-star7.html

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. meta的日常设置

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. [转]Serif和Sans-serif字体的区别

    在西方国家罗马字母阵营中,字体分为两大种类:Sans Serif和Serif,打字机体虽然也属于Sans Serif,但由于是等宽字体,所以另外独立出Monospace这一种类,例如在Web中,表示代 ...

  4. Hbase简单配置与使用

    一. HBase的 二.基于Hadoop的HBase架构 HBase内置有zookeeper,但一般我们会有其他的Zookeeper集群来监管master和regionserver,Zookeeper ...

  5. ionic cordova 安装指定版本

    安装ionic 及 cordova npm install -g cordova ionic npm 淘宝镜像(GFW,导致很多插件下载失败) npm install -g cnpm --regist ...

  6. windows 2012 r2企业版没有界面

    windows 2012 R2系统进去以后只有CMD命令窗口,没有图形化界面,除了cmd其余的全部是黑的.在网上搜了很多,都是大同小异的解决方法,但根本解决不了.今天再这里分享的这个方法很简单,不用重 ...

  7. 安全测试 web应用安全测试之XXS跨站脚本攻击检测

    web应用安全测试之XXS跨站脚本攻击检测 by:授客 QQ:1033553122 说明 意在对XSS跨站脚本攻击做的简单介绍,让大家对xss攻击有个初步认识,并能够在实际工作当中运用本文所述知识做些 ...

  8. C语言程序试题

    一个无向连通图G点上的哈密尔顿(Hamiltion)回路是指从图G上的某个顶点出发,经过图上所有其他顶点一次且仅一次,最后回到该顶点的路劲.一种求解无向图上哈密尔顿回路算法的基础实现如下: 假设图G存 ...

  9. IDisposable

    自己备用 public static class PHDApi : IDisposable { private PHDAccess _phd = null; // Track whether Disp ...

  10. C#操作Exchange配置

    1.客户端配置:运行gpedit.msc进入本地组策略管理器,计算机配置>管理模版>Windows组件>WinRM>WinRM客户端启用允许未加密通信:启用受信任的主机并添加e ...