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 ...
随机推荐
- ThinkPHP 的缓存大概多久更新一次
ThinkPHP 的缓存大概多久更新一次可以自己设置: thinkPHP的缓存默认是文件缓存,保存在Runtime文件夹里面, 如果不设置过期时间,且不清除Runtime文件,就会一直存在. 如果设置 ...
- 763 Hex Conversion
原题网址:http://www.lintcode.com/zh-cn/problem/hex-conversion/ Given a decimal number n and an integer k ...
- http://www.2cto.com/ 红黑联盟
http://www.2cto.com/ 红黑联盟,一个不错的学习或者开阔眼界的网站,内部由中文书写.比较适合国人.
- UVA-307-Sticks-dfs+剪枝
George took sticks of the same length and cut them randomly until all parts became at most 50 units ...
- 小tips: zoom和transform:scale的区别
小tips: zoom和transform:scale的区别 转自 张鑫旭 前端大神 by zhangxinxu from http://www.zhangxinxu.com本文地址:http://w ...
- idea 提交拉取代码,解决冲突
继上两篇文章,本篇重点.所用的都是项目实际操作 提交代码 新建文件提交代码 idea自动提醒你是否加入到本地缓存(点击add就是添加如果不添加提交不上去事后需要手动提交 ps:快捷键是ctrl+alt ...
- 2019-2-17-如何在-Windows-10-中移除-Internet-Explorer-浏览器
title author date CreateTime categories 如何在 Windows 10 中移除 Internet Explorer 浏览器 lindexi 2019-02-17 ...
- Shuffle过程详解
- NoSQL SimpleDB
- 授权指定ip访问mysql 服务器
授权指定ip访问访问 授权ROOT使用密码1234从应用服务器主机连接到mysql服务器 mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'xxx. ...