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基础——Oracle(七)

    一.概述 pl/sql (procedural lanaguage/sql)是 oracle 在标准 sql 上的扩展 .不仅允许嵌入sql 语言,还可以定义变量和常量,允许使用条件语句和循环语句,允 ...

  2. css兼容问题(一)

    开头语:不用就忘,还是自己乖乖的记笔记吧! 正文开始:    (一)如果你的页面对IE7兼容没有问题,又不想大量修改现有代码,同时又能在IE8中正常使用,微软声称,开发商仅需要在目前兼容IE7的网站上 ...

  3. Python全栈学习_day001知识点

    今日大纲: . 变量. ***** . 常量.** . 注释.*** . 基础数据类型初识(int,str,bool). ***** . 用户输入 input ***** . 流程控制语句if. ** ...

  4. 【CSS学习】--- 文本样式

    一.前言 CSS文本属性可以定义文本的外观.通过文本属性,可以定义文本的颜色.字符间距,对齐文本,装饰文本,对文本进行缩进,等等. CSS常用的文本属性目录: text-align 文本对齐属性 te ...

  5. JVM、Gc工作机制详解

    JVM主要包括四个部分: 类加载器(ClassLoad) 执行引擎 内存区: 本地方法接口:类似于jni调本地native方法 内存区包括四个部分: 1.方法区:包含了静态变量.常量池.构造函数等 2 ...

  6. (网页)web性能优化(转)

    转自CSDN: Web性能优化分为服务器端和浏览器端两个方面. 一.浏览器端,关于浏览器端优化,分很多个方面1.压缩源码和图片JavaScript文件源代码可以采用混淆压缩的方式,CSS文件源代码进行 ...

  7. [201804012]关于hugepages 3.txt

    [201804012]关于hugepages 3.txt --//有一段时间我一直强调安装oracle一定要配置hugepage,因为现在的服务器内存越来越大,如果还使用4K的页面表,如果内存表占用内 ...

  8. tkinter中button按钮控件(三)

    button控件 简单的实现: import tkinter wuya = tkinter.Tk() wuya.title("wuya") wuya.geometry(" ...

  9. vue-cli在控制台创建vue项目时乱码的问题

    新装的win10系统,使用vue-cli在控制台创建项目时出现乱码,请问如何处理? 解决: 打开cmd,在控制台输入CHCP 65001,按回车键即可将编码格式设成utf-8,再创建就不会乱码了. 执 ...

  10. apache的php模块讲解以及搭建phpmyadmin管理数据库mysql

    1.php php的包名字叫做php-common,其配置文件使用的是ini风格的格式. php的配置文件以分号作为注释,把分号去掉表示启动此片段功能. 在这里我们可以看到php在apache中的模块 ...