立志用最少的代码做最高效的表达


PAT甲级最优题解——>传送门


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


题意:银行有N个业务窗口,08:00:00点开始办理业务,17:01:00准时停止服务(注意是停止服务,不是停止办理!!!并且17点来仍然可以服务。 也就是说如果17点整来一个人办理一百亿年的服务,仍然可以给他办理。),顾客按顺序排队,求平均等待时间。

明白题意就很好办了,中规中矩的写模拟就行。(方便起见,将循环拆分成最小的时间片段,也就是秒。)


#include <bits/stdc++.h>
using namespace std;
typedef struct {int a_time, p_time;
}record;
int main() {int N, K, cnt = 0, sum = 0;scanf("%d %d", &N, &K);vector<int> time( K, 8 * 60 * 60 );vector<record> rec;for( int i = 0, h, m, s, p; i < N; ++i ) {scanf("%d:%d:%d %d", &h, &m, &s, &p);if( h * 3600 + m * 60 + s <= 17 * 3600 )rec.push_back( { h * 3600 + m * 60 + s, p * 60 } );}sort( rec.begin(), rec.end(), [] ( record a, record b ) { return a.a_time < b.a_time; } );for( int i = 0, min; i < rec.size(); ++i ) {min = 0;for( int j = 0; j < K; ++j )if( time[j] < time[min] ) min = j;if( time[min] > rec[i].a_time ) {sum += time[min] - rec[i].a_time;time[min] += rec[i].p_time;}else time[min] = rec[i].p_time + rec[i].a_time;}printf("%.1f", sum / 60.0 / rec.size() );
}

耗时:


      ——发现光,追随光,成为光,发散光。

1017 Queueing at Bank (25 分)_27行代码AC相关推荐

  1. 【高效解法】1065 单身狗 (25分)_27行代码AC

    立志用更少的代码做更高效的表达 "单身狗"是中文对于单身人士的一种爱称.本题请你从上万人的大型派对中找出落单的客人,以便给予特殊关爱. 输入格式: 输入第一行给出一个正整数 N(≤ ...

  2. 【题意+分析】1071 Speech Patterns (25 分)_27行代码AC

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 People often have a preference among synonyms of the same word. F ...

  3. 1036 Boys vs Girls (25 分)_27行代码AC

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 This time you are asked to tell the difference between the lowest ...

  4. 【简洁代码】1028 List Sorting (25 分)_26行代码AC

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 Excel can sort records according to any column. Now you are suppo ...

  5. 1017 Queueing at Bank (25 分) 【未完成】【难度: 中 / 知识点: 模拟】

    https://pintia.cn/problem-sets/994805342720868352/problems/994805491530579968

  6. 【简便解法】1090 危险品装箱 (25分)_33行代码AC

    立志用最少的代码做最高效的表达 PAT乙级最优题解-->传送门 集装箱运输货物时,我们必须特别小心,不能把不相容的货物装在一只箱子里.比如氧化剂绝对不能跟易燃液体同箱,否则很容易造成爆炸. 本题 ...

  7. 【详细解析】1080 MOOC期终成绩 (25分)_45行代码AC

    立志用更少的代码做更高效的表达 PAT乙级最优题解-->传送门 对于在中国大学MOOC(http://www.icourse163.org/ )学习"数据结构"课程的学生,想 ...

  8. 案例4-1.6 树种统计 (25 分)_18行代码AC

    立志用最少的代码做最高效的表达 随着卫星成像技术的应用,自然资源研究机构可以识别每一棵树的种类.请编写程序帮助研究人员统计每种树的数量,计算每种树占总数的百分比. 输入格式: 输入首先给出正整数N(≤ ...

  9. 【附超时原因】1055 The World‘s Richest (25 分)_42行代码AC

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 Forbes magazine publishes every year its list of billionaires bas ...

最新文章

  1. tplink路由器dns服务器未响应,小米路由器AC2100恢复出厂设置的方法
  2. Runtime应用(三)实现NSCoding的自动归档和自动解档
  3. linux find 反转 查找没有被找到的结果
  4. java audit模块实现_Apollo 源码解析 —— Config Service 操作审计日志 Audit
  5. 程序员编程10大原则,请牢牢记住
  6. 二叉树链表结构表示法
  7. 算法录 之 复杂度分析。
  8. zk宕机掉与客户端连接过程记录
  9. base环境卸载python_20小时快速学习python数据分析实践1——相关软件一系列安装和基本操作熟悉(第0-1h)...
  10. 豆瓣9.8分,周志明的《凤凰架构》,高屋建瓴,推荐(送书)
  11. QQ组件可导致IE10无响应
  12. linux下面java配置,linux下面配置java环境变量
  13. php中html写法,细致说明注解三种PHP嵌套HTML的写法_后端开发
  14. java实现url转码、解码
  15. imdisk虚拟光驱安装linux,imdisk虚拟磁盘驱动器如何加载iso文件?大白菜ImDisk加载iso文件教程...
  16. WPS自动生成目录,目录里显示图片如何解决
  17. html中qq号码怎么写,根据QQ头像hash分析QQ号(html版)
  18. 误差棒是什么?误差柱状图如何做?
  19. 信息安全CIA三要素
  20. Tableau画桑基图

热门文章

  1. 分布式系统概念 | 分布式ID:数据库、号段模式、雪花算法(Snowflake)、Redis实现方案
  2. 用Python实现二叉树的遍历
  3. Netty学习笔记(六)Pipeline的传播机制
  4. IDEA中常用快捷键整理及重置快捷键
  5. 25个实用编程小技巧
  6. 柴树杉:面向数据科学领域的新语言,Go+蓄势待发
  7. Redis主从配置和集群配置
  8. 联捷俞海乐:从技术leader到CEO视野和责任提升几个维度
  9. Serverless.com CEO首次访华!探讨无服务器技术落地
  10. Undefined Reference to Typeinfo