1017 Queueing at Bank (25 point(s))

1017. Queueing at Bank 解析 注意:后面来的顾客是有可能不用排队的。 比如11:00顾客没有了13:00来人了是不用排队的。 在选取窗口的时候方法和之前那个1014的选择方法不同。注意对比。 #include #include #include #include #include #include using namespace std; struct Node { string time; i 阅读详情

1017 Queueing at Bank (25 point(s))

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

思路:

用两个优先队列,分别对顾客队列和窗口进行模拟

注意点:

(1)此处需要的是最小堆,注意使用的STL方式和'<'的重载;

(2)>>不可以重载字符串const char[2],使用getchar();

(3)窗口的结构体表示这个窗口下次开放时间。因此依次从优先队列中取出每一个顾客,如果顾客到达的时间早于窗口开放时间 ,则说明顾客需要等待,窗口下次开放时间是在此基础时间再加上顾客服务所需时间,和顾客到达时间的差值是等待时间;否则说明顾客一到就可以得到服务,窗口下次开放时间是顾客到达时间再加上顾客服务所需时间。窗口服务完成后,需要再将窗口加入到队列中。

(4)值得再复习!

//排队事件的模拟 
#include<iostream>
#include<iomanip>
#include<queue>
#include<map>
using namespace std;
struct Window{//记录窗口下一次开放时间 
	int h,m,s;
	bool operator < (const Window &w)const{//按照hh:mm:ss排序 
		if(h!=w.h) return h>w.h;
		if(m!=w.m) return m>w.m;
		return s>w.s;
	}
}; 
struct Customer{
	int hh,mm,ss,time;
	bool operator < (const Customer &c)const{
		if(hh!=c.hh) return hh>c.hh;
		if(mm!=c.mm) return mm>c.mm;
		return ss>c.ss;
	}
};
priority_queue<Window> win;
priority_queue<Customer> cus;
int main(void){
	int N,K;//N customers K windows
	cin>>N>>K;
	Customer c;
	for(int i=0;i<N;i++){
		cin>>c.hh;getchar();
		cin>>c.mm;getchar();
		cin>>c.ss>>c.time;
		cus.push(c);
	}
	Window w;
	for(int i=0;i<K;i++){
		w.s=w.m=0;w.h=8;
		win.push(w);
	} 
	int totalCus=0;double totalTime=0;
	while(!cus.empty()){
		c = cus.top();
		cus.pop();
		if(c.hh>=17&&(c.mm>0||c.ss>0)) break;
		totalCus++;
		
		w = win.top();
		win.pop();
		if(c.hh<w.h||(c.hh==w.h&&c.mm<w.m)||(c.hh==w.h&&c.mm==w.m&&c.ss<w.s)){
			//如果顾客到达的时间早于窗口开放时间 
			totalTime += (w.h-c.hh)*60.0+(w.m-c.mm)+(w.s-c.ss)/60.0;
			w.m = w.m+c.time;
			w.h += w.m/60;
			w.m %= 60;
		}
		else{//如果顾客到达的时间晚于窗口开放时间,即实际上窗口在等待 
			w.s = c.ss;
			w.m = c.mm + c.time;
			w.h += w.m/60;
			w.m %=60; 
		}
		win.push(w);
		
	}
	//cout<<totalTime<<" "<<totalCus<<endl; 
	printf("%.1f",totalTime/totalCus); 
	return 0;
}

参考链接:

https://blog.youkuaiyun.com/sunbaigui/article/details/8657074

https://blog.youkuaiyun.com/liaotl10/article/details/57594612

https://blog.youkuaiyun.com/wsxyh1071652438/article/details/82469835

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 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 阅读详情

相关推荐

1017 Queueing at Bank (25 point(s))

 题解 与1014类似。不过更加简单。 #include&lt;iostream&gt; #include&lt;algorithm&gt; #include&lt;cstdio&gt; #include&lt;vector&gt; using namespace std; struct node { int ct, t; // come time and spent all time...

徐伯莱 296

ROS相机内参标定详细步骤指南

相机标定的目的是为了确定相机内部参数和外部参数,以便修正图像并将图像坐标映射到世界坐标,或者从世界坐标映射到图像坐标。这个过程是计算机视觉和三维感知任务的关键步骤之一,它有以下主要目的: 1. **减小畸变**:相机镜头和传感器可能引入径向和切向畸变,使得图像中的直线变得弯曲或者物体的形状不准确。通过标定相机,可以矫正这些畸变,使图像更准确。

m0_56661101的博客 1万+

pat1017. Queueing at Bank (25)

1017. Queueing at Bank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Suppose a bank has K windows open for service. There is a yellow line i...

weixin_30301183的博客 239

Window系统下搭建GIT本地服务器

这是一篇在window下搭建git本地服务器的教程,带你一步步搭建出本地的git服务器。

qwer971211的博客 2万+

Claude Desktop Cowork国内实操指南:本地文件自动化办公

大语言模型正从‘问答式AI’迈向‘执行型协作者’,其核心能力在于直接操作本地文件、调用系统工具并嵌入真实工作流。Claude Desktop的Cowork模式正是这一范式的代表,它通过轻量沙箱VM实现对Excel、PPT、PDF、音视频等办公资产的读写与处理,无需手动编码即可完成数据清洗、会议纪要生成、自动化报告输出等任务。技术价值体现在权限可控、环境隔离、结果可交付;典型场景覆盖行政文秘的文档流转、销售运营的数据分析、开发者的脚本调试与环境验证。本文聚焦国内用户高频卡点——网络链路、系统权限与工作流断层,

weixin_30617737的博客 468

1017 Queueing at Bank (25 point(s)) - C语言 PAT 甲级

设计思路: 相当于每个窗口只容纳一人,只需为每个窗口维护一个结束时间 1. 读取数据,根据到达时间排序 2. 遍历 17:00 之前到达的顾客,查询完成时间最早的窗口,则: * 顾客到达时间早于此窗口结束时间:两者之差累加到等待时间,此窗口结束时间累加顾客业务时间 * 顾客到达时间晚于此窗口结束时间:顾客无等待时间,此窗口结束时间更新为顾客到达时间加业务时间

有三只土豆 292

移动端 AI 部署:ONNX Runtime + Android 从模型到 App

移动端 ONNX 部署的流程是 PC 端导出 ONNX → 放到 Android 项目 assets → ONNX Runtime AAR 加载推理。核心是OrtSession,预处理在 Java 层用 Bitmap 操作完成。建议先在 PC 上用 onnxruntime Python 验证模型正确,再集成到 Android 端,可以减少定位问题的时间。ONNX Runtime 自动调用 NNAPI,在主流芯片上不需要额外适配。

know_F0727的博客 73

1017 Queueing at Bank (25 point(s))

1017 Queueing at Bank (25 point(s)) Suppose a bank hasKwindows 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..

专栏 134

华为OD技术面真题 - JAVA开发 - 1

汇总华为OD技术面八股JAVA八股,高频技术真题并提供详细解答。

qq_45776114的博客 1205

专栏二十:如何选择你的单细胞亚群的分辨率--ROGUE

ROGUE这是继chooseR后第二个计算单细胞亚群分辨率的内容,其实关于代码的运行很简单,网上已经有不少教程,重复这些就没意思了,这里主要是结合探讨一下这个算法。

m0_58549466的博客 981

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 in front of the windows which devides the waiting area into two parts. All the customers have to wait...

WangXin Programmer 335

微观交通流仿真软件:SUMO (Simulation of Urban MObility)_(1).SUMO入门与基础概念

SUMO(Simulation of Urban MObility)是一个开源的微观交通流仿真软件,用于模拟城市交通系统中的各种动态行为。SUMO不仅可以模拟车辆的行驶,还可以模拟行人、自行车、公交车等交通参与者的运动。通过SUMO,研究人员和工程师可以对交通系统进行详细建模和分析,从而优化交通规划、评估交通政策和设计智能交通系统。车辆路径规划:SUMO可以模拟车辆在路网中的路径选择,包括动态路径选择和静态路径选择。交通信号控制:支持多种交通信号控制策略,包括固定时间控制、自适应控制等。多模式交通:模拟不同

kkchenjj的博客 1183

1017 Queueing at Bank (25point(s))

1017 Queueing at Bank (25point(s)) #include<cstdio> #include<algorithm> using namespace std; const int maxn = 10010; const int maxk = 110; int N, K; struct Node{ int hh,mm,ss; int time; int process; }customer[maxn]; bool cmp(Node a, Node

LEOSATA's Blog 210

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

PTA甲级 1017 Queueing at Bank (25point(s))

强烈推荐,刷PTA的朋友都认识一下柳神–PTA解法大佬 本文由参考于柳神博客写成 柳神的优快云博客,这个可以搜索文章 柳神的个人博客,这个没有广告,但是不能搜索 还有就是非常非常有用的 算法笔记 全名是 算法笔记 上级训练实战指南 //这本都是PTA的题解 算法笔记 PS 今天也要加油鸭 题目原文 Suppose a bank has K windows open for service. There is a yellow line in front of the windows which d

Huangpengyu123的博客 246

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

PAT A1017 Queueing at Bank (25point(s))

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

qq_42347617的博客 251

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

PAT (Advanced Level) Practice 1017 Queueing at Bank (25 point(s))

题目:PAT A 1017 题目大意 给出N个客户的到达时间,银行有K个窗口,银行在8:00上班,在17:00后到达的客户不服务,也不计算计算到平均时间。请问平均等待时间 解题思路 根据客户达到的时间进行排序。使用window数组模拟银行的窗口。每次分配给你用户的窗口的是时间最小的。 #include<bits/stdc++.h> using namespace std; struct Customer{ int h,m,s,p; int time; }; int n,k;

helloful的博客 184

PAT(A) 1017 Queueing at Bank (25 point(s)) C++ 测试点0,5

注意: 计算平均等待时间时应除以被银行服务的人数,而不是排队的总人数N,否则Case0:Wrong Answer 银行会服务完所有17点前开始排队的顾客,而不是到17点关门,否则Case5:Wrong Answer (Case5中最晚会服务到半夜零点半左右,这什么神仙银行! #include<cstdio> #include<vector> #include<algorithm> #include<cmath> using namespace std;

Anpotan的博客 348

每日两道算法题-|Day14 of PAT--|1017 Queueing at Bank (25point(s))--|结构体排序--|运算符重载 详解

1017 Queueing at Bank (25point(s)) 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 t...

weixin_43661154的博客 240

1017 Queueing at Bank (25分)【模拟,结构体排序】

1017Queueing at Bank(25分) Suppose a bank hasKwindows 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...

胡小涛的博客 271

1017 Queueing at Bank (25分) 最后两个测试点问题

这是一个奇坑无比的题!! 这是一个奇坑无比的题!! 这是一个奇坑无比的题!! 首先我按题目的意思写出来,通过标准案例,然后提交,后两个测试点无法通过。然后我就分析原因。 1.首先是分析得到结果,忽略了统计某些人虽然在17点之前来排队了,但是d到了下班时间仍然没有得到服务。 2.按常理来说,你在排队,排到人家下班时间了,你就应该走了。但是最后一个测试点很有意思,你必须排到队伍第一个人超时服务(服务结束的时间超过了下班时间),然后第一个人结束服务以后(已经在17点之后了),这个时候后面的人才知道自己今天没戏了,

ZiYuTongXue的博客 977

1017 Queueing at Bank (25分)排序水题

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

qq_41773202的博客 179

PAT1017 Queueing at Bank (25分)最后1个测试点的问题

说一下我原先对本题的理解:17:00前来的人在超过17:00后还没被服务就直接回家,这部分人的等待结束时间按17点算。17:00之后来的人直接不计等待时间,也不计人头。 后来看了下题目:**and anyone comes too late (at or after 17:00:01) will not be served nor counted into the average.**题目的意思是,17:00及以前来的那批到17:00时还没被服务的人,哪怕过了17:00也会被继续服务,哪怕银行加班到凌晨也要

ayanna的博客 596

PAT甲级1017 Queueing at Bank (25分) 最后一个测试点未通过

代码如下,看了柳神的代码,思路是一样的,但是找了很久也不知道最后一个点为什么没过。希望有过路的大佬帮我看一下。 #include<iostream> #include<algorithm> using namespace std; struct customer { int arrive_t; int need_t; int serve_start; }; customer customers[10000]; int windows[100]; //记录每个窗口空闲的时间

weixin_41359213的博客 481

PAT 1017. Queueing at Bank

题目:http://pat.zju.edu.cn/contests/pat-a-practise/1017 题解: 模拟题。 代码: #include #include #include #include #include #include #include #include #include using namespace std; #define INF 0x6fffffff stru

Ted's 游乐园 1241

[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 in front of the windows which devides the waiting area into two parts. All the customers have t...

cp0328的博客 3855
上一篇: 1015 Reversible Primes (20 point(s))
下一篇: 1019 General Palindromic Number
coderwait
博客等级 码龄9年 20粉丝 210原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值