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 ...
随机推荐
- socket2里面,有些函数带WSA开头,有些不带。请问有何区别?
WSASocket可以使用WinSock特有功能,比如重叠IO,用dwflags指定. WSA的A是指api,用于区别spi,因为在spi中还有wspsocket,wspaccept等... 在 ...
- 杂项-语言-Swift:Swift
ylbtech-杂项-语言-Swift:Swift Swift,苹果于2014年WWDC(苹果开发者大会)发布的新开发语言,可与Objective-C*共同运行于Mac OS和iOS平台,用于搭建基于 ...
- Delphi代码创建形式规范 1.0
Delphi代码创建形式规范 1.0 本规范的目的:给自己的代码一个统一而标准的外观,增强 可读性,可理解性,可维护性 本规范的原则:名称反映含义,形式反映结构 1.单元风格 ...
- Mysql优化系列之查询性能优化前篇2
接前一篇,这一篇主要总结下几个经常要用的命令 命令一:explain+sql mysql> explain select * from servers; +----+-------------+ ...
- SpringCloud学习笔记《---01 概念 ---》篇
- LUA中的冒号、点和self
在Lua编程中,经常会看到有时用点号定义一个table的成员函数,有时却用冒号,在调用的时候也是如此.那么点号和冒号在使用上有什么区别呢?它们与self之间又是什么样的关系呢?稍安勿躁,接下来谜底将一 ...
- linux普通用户无法登录mysql
一.前言 本帖方法只适用于普通用户无法登录,但root用户可以登录的情况. 今天将war包放入linux后,运行报错,经过检查发现是数据库连接不上.奇怪的是,用户名和密码都是正确的,所以有了以下发现. ...
- T2963 贪吃蛇【BFS,四进制状压,A*】
Online Judge:未知 Label:BFS,四进制状压,暴力,A*,哈希,玄学. 题目描述 给定一个n*m的地图和蛇的初始位置,地图中有些位置有石头,蛇不能经过.当然蛇也不能爬到地图之外. 每 ...
- C++构造与析构函数中调用虚函数的问题
前些天想把以前写的内存池算法重写一遍,跨平台是第一目标,当时突发奇想,因为不愿意做成一大堆#if..#end,所以想利用C++的多态性,但是怎么让内存池完好退出却没想到自认为完美的方案.但是一个很偶然 ...
- 84 落单的数 III
原题网址:http://www.lintcode.com/zh-cn/problem/single-number-iii/# 给出2*n + 2个的数字,除其中两个数字之外其他每个数字均出现两次,找到 ...