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 (≤104) - 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

思路

把每个时间都转换为秒,方便比较大小。

按照到达时间进行排序,把到达时间大于17*3600的直接不予考虑。

用一个vector记录每个窗口可以接待用户的时间。

​ 一开始时,每个窗口的可以接待用户的时间都是8*3600

​ 从第一个顾客开始扫描到最后一个顾客,令t为所有窗口中最早结束的时间,c[i].t为第i个顾客到达的时间,c[i].cost为第i个顾客办理业务的时间,sum记录所有顾客等待的时间,则

​ 若c[i].t > t ,则 t = c[i].t + c[i].cost

​ 否则,t += c[i].cost, sum += t - c[i].t

答案就是sum/60.0/N (N为删除到达时间在17*3600之后的顾客人数)

代码

#include <stdio.h>
#include <string>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <functional>
#include <limits.h>
using namespace std; struct customer{
int t;
int cost;
bool operator< (customer a) const {
return t < a.t;
}
}; int N, K;
customer c[10000 + 10];
priority_queue<int, vector<int>, greater<int> > myq;
vector<int> myv;
int sum = 0;
int main() {
//input
cin >> N >> K;
int h, m, s, cost;
for(int i = 0; i < N; i++){
scanf("%d:%d:%d%d", &h, &m, &s, &cost);
c[i].t = h * 3600 + m * 60 + s;
c[i].cost = min(60 * 60, cost * 60);
} // init
sort(c, c + N);
for(int i = N - 1; i >= 0; i--){
if(c[i].t > 17 * 3600) N--;
}
for(int i = 0; i < K; i++){
myv.push_back(8 * 3600);
} // do it
for(int i = 0; i < N; i++){
vector<int>::iterator j = min_element(myv.begin(), myv.end());
if(*j < c[i].t){
*j = c[i].t + c[i].cost;
}
else{
sum += *j - c[i].t;
*j += c[i].cost;
}
}
printf("%0.1lf", sum / 60.0 / N);
return 0;
}

PAT 1017 Queueing at Bank (模拟)的更多相关文章

  1. PAT 1017 Queueing at Bank (模拟)

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

  2. PAT 1017 Queueing at Bank[一般]

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

  3. pat——1017. Queueing at Bank (java中Map用法)

    由PAT1017例题展开: Suppose a bank has K windows open for service. There is a yellow line in front of the ...

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

  5. PAT 1017. Queueing at Bank

    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 (25 分)(模拟题,有点思维小技巧,第二次做才理清思路)

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

  7. PAT甲级1017. Queueing at Bank

    PAT甲级1017. Queueing at Bank 题意: 假设一家银行有K台开放服务.窗前有一条黄线,将等候区分为两部分.所有的客户都必须在黄线后面排队,直到他/她轮到服务,并有一个可用的窗口. ...

  8. PAT甲题题解-1017. Queueing at Bank (25)-模拟

    有n个客户和k个窗口,给出n个客户的到达时间和需要的时长有空闲的窗口就去办理,没有的话就需要等待,求客户的平均时长.如果在8点前来的,就需要等到8点.如果17点以后来的,则不会被服务,无需考虑. 按客 ...

  9. PAT (Advanced Level) 1017. Queueing at Bank (25)

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

随机推荐

  1. Chrome 提标 您的浏览器限制了第三方Cookie...解决方法

    最近升级Chrome后会出现  您的浏览器限制了第三方Cookie,这将影响您正常登录,您可以更改浏览器的隐私设置,解除限制后重试. 解决方法: chrome://flags/ 把这句复制到浏览器回车 ...

  2. SequoiaDB 巨杉数据库Docker镜像使用教程

    为方便用户快速体验,SequoiaDB 巨杉数据库提供基于 Docker 的镜像.本文介绍如何在 Docker 环境下部署 SequoiaDB 分布式集群环境.   集群规划 我们准备在五个容器中部署 ...

  3. HTTP慢速攻击

    漏洞原理 HTTP慢速攻击也叫slow http attack,是一种DoS攻击的方式.由于HTTP请求底层使用TCP网络连接进行会话,因此如果中间件对会话超时时间设置不合理,并且HTTP在发送请求的 ...

  4. LitElement(六)生命周期

    1.概述 基于LitElement的组件通过响应观察到的属性更改而异步更新. 属性更改是分批进行的,如果在请求更新后,更新开始之前,发生更多属性更改,则所有更改都将捕获在同一次更新中. 在较高级别上, ...

  5. Centos7下配置Apache的虚拟主机

    一.虚拟主机 虚拟主机是Apache提供的一个功能,通过虚拟主机拉雅在一台服务器上部署多个网站.虽然服务器的IP地址是相同的,但用户当用户使用不同的域名访问时,访问到的是不同的网站. 下面讲解Apac ...

  6. AcWing 前缀和 一维加二维

    一维 #include<bits/stdc++.h> using namespace std; ; int n,m; int a[N],s[N]; int main(){ ios::syn ...

  7. mysql 查询时间戳格式化 和thinkphp查询时间戳转换

    我在网上看了好多写的,都差不多,甚至好多都是一个人写的被别人转载啥的,哎 我写一个比较简单的 1.mysql语句 格式化时间戳 select id,name,FROM_UNIXTIME(time,'% ...

  8. 解决“(1146, "Table 'mydb.django_session' doesn't exist")”报错的方法

    执行 ./manage.py makemigrations sessions ./manage.py migrate sessions

  9. HBase 中读 HDFS 调优

    HDFS Read调优 在基于 HDFS 存储的 HBase 中,主要有两种调优方式: 绕过RPC的选项,称为short circuit reads 开启让HDFS推测性地从多个datanode读数据 ...

  10. HDU4714 Tree2cycle 解题报告

    题意 给定一棵无根树,删除或连接一条边的代价为\(1\),求把树变为环的最小代价. 前置思路 如果删除了\(k\)条边,使得树变成\((k+1)\)条链,再用\((k+1)\)次连接操作把树变成一个环 ...