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 (≤10​4​​) - 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的更多相关文章

  1. PAT甲级1017. Queueing at Bank

    PAT甲级1017. Queueing at Bank 题意: 假设一家银行有K台开放服务.窗前有一条黄线,将等候区分为两部分.所有的客户都必须在黄线后面排队,直到他/她轮到服务,并有一个可用的窗口. ...

  2. 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 ...

  3. 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 ...

  4. PAT 1017 Queueing at Bank[一般]

    1017 Queueing at Bank (25)(25 分)提问 Suppose a bank has K windows open for service. There is a yellow ...

  5. PAT 1017 Queueing at Bank (模拟)

    1017. Queueing at Bank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Supp ...

  6. PAT甲级1017题解——模拟排序

    题目分析: 本题我第一次尝试去做的时候用的是优先队列,但是效率不仅代码量很大,而且还有测试样例过不去,很显然没有找到一个好的数据结构来解决这道题目(随着逐渐的刷PAT甲级的题会发现有时选择一个好的解题 ...

  7. 【PAT甲级】1017 Queueing at Bank (25 分)

    题意: 输入两个正整数N,K(N<=10000,k<=100)分别表示用户的数量以及银行柜台的数量,接下来N行输入一个字符串(格式为HH:MM:SS)和一个正整数,分别表示一位用户到达银行 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 老男孩Python全栈视频

    链接:https://pan.baidu.com/s/1c1JOCL1w-vnYGkrhElk_GQ 密码私聊我

  2. hadoop学习笔记壹 --环境搭建及配置文件的修改

    Hadoop生态和其他生态最大的不同之一就是“单一平台多种应用”的理念了. hadoop能解决是什么问题: 1.HDFS :海量数据存储 MapReduce: 海量数据分析   YARN :资源管理调 ...

  3. 分布式缓存技术redis系列(三)——redis高级应用(主从、事务与锁、持久化)

    上文<详细讲解redis数据结构(内存模型)以及常用命令>介绍了redis的数据类型以及常用命令,本文我们来学习下redis的一些高级特性. 安全性设置 设置客户端操作秘密 redis安装 ...

  4. 如何在一台机器上部署多个tomcat

    1,在/usr/local/下部署两个tomcat7. 2,修改/etc/profile文件,加入下面内容 vi  /etc/profile export JAVA_HOME=/usr/java/jd ...

  5. 斯坦福HAI—细数全球18件AI大事记

    3 月 18 日,由李飞飞担任所长之一的「以人为本人工智能研究所」(HAI)自启动以来不短的时间后,终于完成了正式成立的高光时刻.而正式上线的官网日前也更新了两条博文,一篇是详尽介绍 HAI 的文章: ...

  6. http协议以及get和post请求

    HTTP协议是网络传输信息的一种规范. 就好比两个人之间的交流,甲只会讲英语,乙只会说汉语,结果是他们必然无法开怀畅谈. HTTP协议也类   GET 请求获取 Request-URI 所标识的资源 ...

  7. 在模拟器上运行Android项目时报错:DELETE_FAILED_INTERNAL_ERROR Error while Installing APKs

    今天在Android Studio自带的模拟器上运行项目的时候,出现如下所示Error:当点击ok后,发现模拟器不能运行程序. 解决办法: 更改Android Studio中的设置: File---& ...

  8. jmeter(三)SOAP/XML-RPC Request

    项目背景:公司的微信端H5界面新开发了会员注册功能,需要对其进行压力测试 项目目标:需要承受每分钟最少6000的压力 一.建立一个测试计划(test plan) 之前有说过,jmeter打开后会自动生 ...

  9. VD: error VERR_FILE_NOT_FOUND

    virtualbox制作的镜像文件如果移动了位置,比如从C盘移到D盘,那么再次打开时会提示找不到文件. 解决办法: 打开virtualbox,在“管理”菜单中打开“虚拟介质管理”,在“虚拟硬盘”选项卡 ...

  10. C# 中堆与栈的浅记

    C# 中堆与栈的浅记 什么是堆和栈? 简言之.堆和栈是驻留在内存中的区域,它们的作用是帮助我们运行代码.在.Net Framework 环境下,当我们的代码运行时,内存中的堆和栈便存储了这些代码,并包 ...