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. sql server 压缩备份数据库

    转自 https://www.cnblogs.com/527289276qq/p/6273291.html 今天需要把一个省外项目的数据库从服务器上备份.拷贝到本机(跨地域传输数据库备份文件). 连上 ...

  2. ORB-SLAM2(1) Linux下配置和编译

    ORB-SLAM2 官网:https://github.com/raulmur/ORB_SLAM2 配置教程:http://blog.csdn.net/zzlyw/article/details/54 ...

  3. 2017-2018-2 20155314《网络对抗技术》Exp4 恶意代码分析

    2017-2018-2 20155314<网络对抗技术>Exp4 恶意代码分析 目录 实验要求 实验内容 实验环境 基础问题回答 预备知识 实验步骤 1 静态分析 1.1 使用virsca ...

  4. HTML5的快速使用和css3的入门知识汇总

    各位开发者朋友和技术大神大家好!博主刚开始学习html5 ,自本周开始会每周更新技术博客,与大家分享每周所学.鉴于博主水品有限,如发现有问题的地方欢迎大家指正,有更好的意见和建议可在评论下方发表,我会 ...

  5. 华为交换机常用命令(以s5700-SI为例)

    交换机的三种模式: Access模式: 一般用来连接计算机与交换机. 此模式下有一个PVID就是本端口所属的VLAN号,如果从链路上收到无标签的帧,则打上默认VLAN号,然后发给其他端口,如果从链路上 ...

  6. springboot读取配置文件的顺序(转)

    也就是说:springboot会默认先加载项目外部的配置文件,覆盖内部的配置文件!所以导致项目一直使用的错误的配置! 强烈建议:不要把项目和application.properties配置文件放在一起

  7. Linux上VsCode编译打包运行

    前提:最好使用root用户可以排除一些不必要的错误. 一. 准备环境 Node.js(>= 8.12.0, < 9.0.0) Python2.7 Yarn(可以通过npm install ...

  8. 笔记二:常用的h5语义化标签

    0.前言: 所谓语义化标签就是一种 我们仅通过标签名就能判断出该标签内容的语义的标签,见名知意. 总结这部分内容,主要是为了能从繁琐的div嵌套div中,改成带有h5标签码.这样更有利于读写代码. 人 ...

  9. centos 7 安装python3.5.1

    系统: [root@localhost ~]# cat /etc/centos-release CentOS Linux release 7.2.1511 (Core) 内核: [root@local ...

  10. MySQL 误操作后如何快速恢复数据~!~!~

    基本上每个跟数据库打交道的程序员(当然也可能是你同事)都会碰一个问题,MySQL误操作后如何快速回滚?比如,delete一张表,忘加限制条件,整张表没了.假如这还是线上环境核心业务数据,那这事就闹大了 ...