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 ...
随机推荐
- webstorm 初次上传代码到 远程gitlab中
1. 在 公司搭建的gitlab网站,创建project,然后生成了 git的地址. 2.在 本地电脑上,打开 webstorm,要将已有的代码上传到 git网站,那么需要在webstrom编辑器的t ...
- vue之.native修饰符
.native 修饰符就是用来注册元素的原生事件而不是组件自定义事件的 比如:自定义 Button.vue 组件 <template> <button type="butt ...
- 搞笑:Java & PHP & C++ 之间的战斗!
Java 拥有十八般武艺,PHP一招致命!PHP 果然是世界上最好的编程语言~ Java 连老将 C++ 也干不过,直接一招 KO,我也是醉了... 这里并不是贬低Java,只有资深老司机能看懂的图吧 ...
- C# 字符串string和内存流MemoryStream及比特数组byte[]之间相互转换
定义string变量为str,内存流变量为ms,比特数组为bt 1.字符串转比特数组 复制代码 代码如下: (1)byte[] bt=System.Text.Encoding.Default.GetB ...
- springcloud(十六)、feign+hystrix+ribbon+zuul应用案例
在 基于 " sringcloud(十四).ribbon负载均衡策略应用案例 "所有工程的基础上,进行如下操作进行网关设置 1.创建eureka-client-consumer-z ...
- jsp 引入js、css修改后有缓存不及时更新
解决:(增加随机版本号) <link rel="stylesheet" type="text/css" href="css/1.css?v=&l ...
- JS流程控制语句 多重判断满足你各种需求 要在多组语句中选择一组来执行,使用if..else嵌套语句。
多重判断(if..else嵌套语句) 要在多组语句中选择一组来执行,使用if..else嵌套语句. 语法: if(条件1) { 条件1成立时执行的代码} else if(条件2) { 条件2成立时执行 ...
- datetime与timestamp相互转换
select unix_timestamp('2019-12-05 12:26:35'); );
- 关于Cadence SPB 16.6 破解的一些关键步骤
网上搜索到的破解方法,一般来说流程都是没有什么大问题的.较详细的一个破解流程可参照: http://www.mr-wu.cn/cadence-orcad-allegro-spb-16-6-instal ...
- 2016.10.6初中部上午NOIP普及组比赛总结
2016.10.6初中部上午NOIP普及组比赛总结 中了病毒--病毒--病毒-- 进度: 比赛:AC+0+0+20=120 改题:AC+0+AC+20=220 Stairs 好--简--单!递推就过了 ...