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 (≤) - the total number of customers, and K (≤) - 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 <iostream>
#include <vector>
#include <algorithm> using namespace std; struct Person
{
int arriveTime, serverTime, popTime;
}; int N, K; int main()
{
cin >> N >> K;
vector<Person*>window(K);//就排一个人办业务,不需要用队列
vector<Person*>data;
double waitTime = 0.0;
for (int i = ; i < N; ++i)
{
int hh, mm, ss, tt;
Person* one = new Person;
scanf("%d:%d:%d %d", &hh, &mm, &ss, &tt);
one->arriveTime = hh * + mm * + ss;
one->serverTime = tt * ;
if (one->arriveTime <= ( * ))//下班了,不算
data.push_back(one);
}
sort(data.begin(), data.end(), [](Person* a, Person* b) {return a->arriveTime < b->arriveTime; });
for (int i = ; i < data.size(); ++i)
{
if (i < K)
{
if (data[i]->arriveTime < ( * ))//来早了
waitTime += * - data[i]->arriveTime;
data[i]->popTime = data[i]->serverTime + (data[i]->arriveTime < ( * ) ? * : data[i]->arriveTime);
window[i%K] = data[i];
}
else
{
int index = , minTime = window[]->popTime;
for (int j = ; j < K; ++j)
{
if (minTime > window[j]->popTime)
{
index = j;
minTime = window[j]->popTime;
}
}
waitTime += data[i]->arriveTime < minTime ? (minTime - data[i]->arriveTime) : ;//早到就等待
data[i]->popTime = data[i]->serverTime + (data[i]->arriveTime < minTime ? minTime : data[i]->arriveTime);
window[index] = data[i];
}
}
if (data.size() == )
printf("0.0\n");
else
printf("%0.1f\n", (waitTime / ( * data.size())));
return ;
}

PAT甲级——A1017 Queueing at Bank的更多相关文章

  1. PAT甲级1017. Queueing at Bank

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

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

  3. PAT 甲级 1017 Queueing at Bank

    https://pintia.cn/problem-sets/994805342720868352/problems/994805491530579968 Suppose a bank has K w ...

  4. PAT A1017 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] A1017 Queueing at Bank

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

  6. A1017. Queueing at Bank

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

  7. PAT甲级题解分类byZlc

    专题一  字符串处理 A1001 Format(20) #include<cstdio> int main () { ]; int a,b,sum; scanf ("%d %d& ...

  8. PAT 1017 Queueing at Bank[一般]

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

  9. PAT 1017 Queueing at Bank (模拟)

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

随机推荐

  1. 转:Linux环境下段错误的产生原因及调试方法小结

    源地址:http://www.cnblogs.com/panfeng412/archive/2011/11/06/2237857.html 补充:http://baike.baidu.com/link ...

  2. 如何查找一个命令由哪个rpm安装&&rpm 的相关查询方法

    [root@test-can-nginx src]# which python3 /usr/bin/python3 [root@test-can-nginx src]# rpm -qf /usr/bi ...

  3. 19.SimLogin_case05

    # 使用自造的cookies登录马蜂窝 import requests from lxml import etree str = 'mfw_uuid=5bcfcc20-b235-fbbe-c1d6-a ...

  4. <Django> 第三方扩展

    1.富文本编辑器 tinymce为例 安装 pip install django-tinymce 在settings.py中的配置 配置应用 INSTALLED_APPS = [ 'django.co ...

  5. Lua程序设计之字符串精要

    (摘自Lua程序设计) 基本: Lua语言的字符串是一串字节组成的序列. 在Lua语言中,字符使用8个比特位来存储. Lua语言中的字符串可以存储包括空字符在内的所有数值代码,这意味着我们可以在字符串 ...

  6. linux 系统优化初始化配置

    一.系统优化配置 1.修改yum源  配置国内yum源 阿里云yum源地址 #CentOS 5.x wget -O /etc/yum.repos.d/CentOS-Base.repo http://m ...

  7. dea死锁处理和大事务处理

    死锁处理流程: show full processlist; # 获得当前所有数据库连接 select id, db, user, host, command, time, state, info f ...

  8. 六. Default arguments 参数默认值

    示例: 注意点:函数是会默认声明参数变量的,所以不需要再重新声明一次,否则会报错 错误示例如下: 函数参数的传值方法: 需要注意的是:如果要给第二个参数传值,那第一个参数要传undefined,而不能 ...

  9. 爆表!猜猜这个大会的IQ总值有多高?

    “人人可及的未来,同样存在于「日拱一卒」的琐碎生活当中,那也是技术对生活最为直观的改变和演进.” “以通神明之德,以类万物之情”,这句来自<易经>的话,放到现今也合宜. 人类掌控事物发展的 ...

  10. Ubuntu GitHub操作——创建仓库

    一.创建仓库 1.初始化仓库(只在初始化时执行一次) git init 这部是新建并初始化仓库 2.向仓库中添加文件 git add . 将文件夹内的所有文件都添加到仓库中(注意小“.”),在这部之后 ...