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. Java框架之Struts2(六)

    一.OGNL表达式语言 Ognl Object Graphic Navigation Language(对象图导航语言),它是一种功能强大的表达式语言(Expression Language,简称为E ...

  2. webstrom vue项目让局域网访问

    vue项目package.json "dev": "webpack-dev-server --inline --progress --config build/webpa ...

  3. 小程序webview应用实践

    原文:小程序webview实践 作者:张所勇(转转开放业务部前端负责人) 公众号:大转转FE Fundebug经授权转载,版权归原作者所有. 大家好,我是转转开放业务部前端负责人张所勇,今天主要来跟大 ...

  4. javaSE总结

    1 java的历史 1991-至今  詹姆斯-高斯林  SUN公司 ORACLE 2009年 2 java的版本 javaSE  java的标准桌面级开发 javaEE  企业级web开发 javaM ...

  5. React中props

    今天让我们开启新的篇章好吧,来搞一搞React,以下所有操作都是我个人的一些理解,如果有错吴还请指出,想要看更全的可以去React官网可能一下子好吧 昨天按摩没到位,导致今天身体不太行,撸码千万别苦了 ...

  6. python之锁, 队列

    进程的其他方法 进程id,进程名字,查看进程是否活着is_alive()  terminate()发送结束进程的信号 import time import os from multiprocessin ...

  7. svg简介与使用

    什么是svg SVG是"Scalable Vector Graphics"的简称.中文可以理解成"可缩放矢量图形". 可缩放矢量图形是基于可扩展标记语言(标准通 ...

  8. 异步 Apex 类

    异步Apex类 一个Apex类可以定义为异步类,用于异步执行. 异步类可以通过多种方式实现: Future注解 批处理 Queueable接口 Schedulable接口 Future注解 使用Fut ...

  9. 商业智能BI-基础理论知识总结 ZT

    因为要加入一个BI项目,所以最近在研究BI相关的知识体系,由于这个方面的知识都是比较零散,开始都很多概念,不知道从何入手,网上找的资料也不多,特别是实战案例方面更少,这里还是先把理论知识理解下吧,分享 ...

  10. js判断当前浏览器语言类型

    console.log(window.navigator.language.slice(0, 2)); 得到的是zh