PAT甲级——A1017 Queueing at Bank
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的更多相关文章
- PAT甲级1017. Queueing at Bank
PAT甲级1017. Queueing at Bank 题意: 假设一家银行有K台开放服务.窗前有一条黄线,将等候区分为两部分.所有的客户都必须在黄线后面排队,直到他/她轮到服务,并有一个可用的窗口. ...
- 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 ...
- PAT 甲级 1017 Queueing at Bank
https://pintia.cn/problem-sets/994805342720868352/problems/994805491530579968 Suppose a bank has K w ...
- 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 ...
- [PAT] A1017 Queueing at Bank
[思路] 1:将所有满足条件的(到来时间点在17点之前的)客户放入结构体中,结构体的长度就是需要服务的客户的个数.结构体按照到达时间排序. 2:wend数组表示某个窗口的结束时间,一开始所有窗口的值都 ...
- A1017. Queueing at Bank
Suppose a bank has K windows open for service. There is a yellow line in front of the windows which ...
- PAT甲级题解分类byZlc
专题一 字符串处理 A1001 Format(20) #include<cstdio> int main () { ]; int a,b,sum; scanf ("%d %d& ...
- PAT 1017 Queueing at Bank[一般]
1017 Queueing at Bank (25)(25 分)提问 Suppose a bank has K windows open for service. There is a yellow ...
- PAT 1017 Queueing at Bank (模拟)
1017. Queueing at Bank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Supp ...
随机推荐
- 手工编写JavaWeb项目
手工编写JavaWeb项目 一.打开Tomcat服务器 二.编写简单的web项目 三.访问项目 并且,tomcat服务器也是可以直接访问.txt的,其实就和其它的web服务器一样,什么都可以访问,和之 ...
- Hadoop yarn任务调度策略介绍
二.Capacity Scheduler(容器调度器)的配置 2.1 容器调度介绍 Capacity 调度器允许多个组织共享整个集群,每个组织可以获得集群的一部分计算能力.通过为每个组织分配专门的队列 ...
- System.Web.Mvc.HttpPatchAttribute.cs
ylbtech-System.Web.Mvc.HttpPatchAttribute.cs 1.程序集 System.Web.Mvc, Version=5.2.3.0, Culture=neutral, ...
- Keras+Yolo 目标检测
参考:https://www.cnblogs.com/tensorflownews/p/8922359.html Github:https://github.com/qqwweee/keras-yol ...
- laravel装饰者模式例子
interface Decorator{ public function display(); } class XiaoFang implements Decorator { private $nam ...
- 万恶之源-python介绍
PATH OF PYTHON (生命短暂,我要学pythonヾ(◍°∇°◍)ノ゙) 一.Python介绍: 简史:Python诞生于1989年的圣诞节, 创始人为Guido van Rossum, 又 ...
- ubuntu常见错误–Could not get lock /var/lib/dpkg/lock解决
ubuntu常见错误–Could not get lock /var/lib/dpkg/lock解决 通过终端安装程序sudo apt-get install xxx时出错: E: C ...
- spring AOP 编程--AspectJ注解方式 (4)
1. AOP 简介 AOP(Aspect-Oriented Programming, 面向切面编程): 是一种新的方法论, 是对传统 OOP(Object-Oriented Programming, ...
- vue表格之tableHeaderColor(修改表头背景色)
<el-table :header-cell-style="tableHeaderColor"></el-table> // 更改表头样式 tableHea ...
- netty http 服务器
HttpFileServer package com.zhaowb.netty.ch10_1; import io.netty.bootstrap.ServerBootstrap; import io ...