PAT 甲级 1017 Queueing at Bank
https://pintia.cn/problem-sets/994805342720868352/problems/994805491530579968
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 (≤104) - the total number of customers, and K (≤100) - 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 <bits/stdc++.h>
using namespace std; int N, M; struct Node{
int time;
int wait;
}; vector<Node> v; bool cmp(const Node &a, const Node &b) {
return a.time < b.time;
} int main() {
scanf("%d%d", &N, &M);
for(int i = 0; i < N; i ++) {
Node n;
int h, m, s, t;
scanf("%d:%d:%d %d", &h, &m, &s, &t);
n.time = h * 3600 + m * 60 + s;
n.wait = t * 60; if(n.time <= 61200) v.push_back(n);
} vector<int> win(M, 28800);
//memset(win, 28800, sizeof(win));
sort(v.begin(), v.end(), cmp); //for(int i = 0; i < v.size(); i ++)
//printf("%d %d\n", v[i].time, v[i].wait); double total = 0.0;
for(int i = 0; i < v.size(); i ++) {
int temp = 0, minn = win[0];
for(int j = 1; j < M; j ++) {
if(win[j] < minn) {
minn = win[j];
temp = j;
}
}
if(win[temp] <= v[i].time)
win[temp] = v[i].time + v[i].wait;
else {
total += (win[temp] - v[i].time);
win[temp] += v[i].wait;
}
} //cout << total;
if(v.size() == 0) printf("0.0\n");
else printf("%.1lf\n", total / 60.0 / v.size());
return 0;
}
把所有时间转换成秒 把来的人按照来的时间排序 在 17:00:00 之后的排除 更新最快结束的窗
PAT 甲级 1017 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甲级——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 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 ...
- PAT甲级1017题解——模拟排序
题目分析: 本题我第一次尝试去做的时候用的是优先队列,但是效率不仅代码量很大,而且还有测试样例过不去,很显然没有找到一个好的数据结构来解决这道题目(随着逐渐的刷PAT甲级的题会发现有时选择一个好的解题 ...
- 【PAT甲级】1017 Queueing at Bank (25 分)
题意: 输入两个正整数N,K(N<=10000,k<=100)分别表示用户的数量以及银行柜台的数量,接下来N行输入一个字符串(格式为HH:MM:SS)和一个正整数,分别表示一位用户到达银行 ...
- pat——1017. Queueing at Bank (java中Map用法)
由PAT1017例题展开: Suppose a bank has K windows open for service. There is a yellow line in front of the ...
- PAT 1017. Queueing at Bank
Suppose a bank has K windows open for service. There is a yellow line in front of the windows which ...
随机推荐
- 如何使用openscad绘制一个简单的键帽.
1 新建空项目 2测数据 测量得出数据.这个长方体的长宽高分别是1.6.4.6.8 注意,这三个数据并不是测量得到的数据,而且加了一点公差值(为3D打印做准备) 3画图 写代码 导入模型 为了方便以后 ...
- 你不得不知道的 .NET CORE —— .NET Framework, .NET Core 和 .NET Standard 的区别
.NET Framework 和 .NET Core 是平台应用框架,而 .NET Standard 是 .NET 底层库.因此只要用 .NET Standard 工程来写的代码可以直接在上层的平台应 ...
- css学习之样式层级和权重
第一种情况 当选择器相同的情况下,引入方式的前后,决定页面最后的效果 ---------外部在最后面显示 ---------内部在最后面显示 第二种情况 引入方式相同时候,则是按照权重取最大(取权重最 ...
- alios-things makefile
https://blog.csdn.net/crazyskady/article/details/80849765 MAKEFILE下面这句:CFLAGS=-I/home/develop/includ ...
- Mybatis学习总结(二)——Mapper代理开发
一.概要 1.原始DAO开发中存在的问题:(1)DAO实现方法体中存在很多过程性代码.(2)调用SqlSession的方法(select/insert/update)需要指定Statement的id, ...
- [07] 使用注解完成IOC配置
1.扫描配置 之前使用的Spring的Bean管理都是通过xml的配置文件来操作的,在Spring3.0之后已经引入了注解形式,Spring可以在指定路径下进行扫描,寻找标注了@Component.@ ...
- VS2015编写的MFC上位机,波特率可调,可动态显示曲线,可显示三维
VS2015编写的MFC上位机,波特率可调,可动态显示曲线,可显示三维 2016年01月14日 11:40:28 博博有个大大大的Dream 阅读数:9375 版权声明:本文为博主原创文章,未经博 ...
- springbootAdmin+eureka集群+swagger
请移步githubb下载源码.知识共享.(https://github.com/yivvonllh) 或者直接git下载(https://github.com/yivvonllh/spring-clo ...
- sql新语句
SQL语句查找重复数据的写法: select partner_id,* from sale_origin where partner_id in (select partner_id from ...
- JQuery将form表单值转换成json字符串函数
由于后台接口限定,必须要将表单内容转换成json字符串提交,因此写了一个将form表单值转成json字符串的函数. 前提:页面引入了JQuery 下面直接上代码 一.代码 / ...