PAT 甲级 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 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 (≤) - the total number of customers, and K (≤) - 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
题目大意:
这题主要是模拟客户等待的平均时间,按照先来先服务的原则,并且在17:00:01后到来的客户无法进行服务,每个窗口只能有一个人。
17:00:00及以前到的一定要继续服务完。
思路:
1.统一都用s计,8点是28800s,17点是61200s
2.按来的时间排序,数组中只要存两个数即可:s开始服务的时间,t服务所需的时间。
3.怎么算每个人等了多久呢(这个人等的时间不包括他自己办理业务的时间)
第一批人(k个人)的等待时间:如果早于8点,那么等待时间为 28800-s
晚于 ,他来的时候还有位置空着,等待时间为0
之后的人的等待时间,是有规律的。
先在q中挑出mint,谁办完了,就把位置让掉,然后把等待的人群a里面最前的那个人挑出来,放到q中空缺的位置,计算这个人的等待时间

4.注意!考虑没有人的情况,此时分母为0!!!
一遍过AC代码:
#include<bits/stdc++.h>
using namespace std;
struct node{
int s;
int t;
}a[];//在等待的人们
node q[];//在办业务的人们
bool cmp(node &x,node &y){
return x.s<y.s;
}
int main()
{
int n,k;
cin>>n>>k;
for(int i=;i<=n;i++){
int h,m,s;
double t;
scanf("%2d:%2d:%2d %lf",&h,&m,&s,&t);
a[i].s=h*+m*+s;//开始的时刻
a[i].t=int(t*);//需要花多久
if(a[i].t>){//每个人最多60分钟
a[i].t=;
}
}
sort(a+,a+n+,cmp);
/*for(int i=1;i<=n;i++){
cout<<a[i].s<<" "<<a[i].t<<endl;
} */ //初始化
double sum=;//等待的总时间
int p_sum=;//人数
for(int i=;i<=n;i++)
{
if(i<=k)
{
p_sum++;
if(a[i].s<=){
sum+=-a[i].s;
//cout<<"第"<<a[i].s<<"人"<<"等了 "<<28800-a[i].s<<endl;
a[i].s = ;
}
q[i].t=a[i].t;
q[i].s=a[i].s;
}else{
q[i].s=;
}
} int p=k+;//p代表下一个轮到谁了
int mint=;
while(p<=n){//还有人在等着办业务
if(a[p].s>) {//超过17点了
break;
}
//挑出队列中结束时间最早的时刻mint
int mint=;
for(int i=;i<=k;i++){
if(q[i].s+q[i].t<mint)
{
mint=q[i].s+q[i].t;
}
}
//cout<<"mint "<<mint<<endl;
//跳到mint这一时刻
for(int i=;i<=k;i++){
if(q[i].s+q[i].t==mint){
//第qi个人换成第p个人
q[i].s=a[p].s;
q[i].t=a[p++].t;
p_sum++;
if(mint>q[i].s){
sum+=mint-q[i].s;
//cout<<"第"<<q[i].s<<"人"<<"等了 "<<mint-q[i].s<<endl;
q[i].s=mint;//这个人的开始时间不再是原来的了
}
}
}
}
if(p_sum!=){
sum=sum/p_sum;
sum=sum/;
}
else{//特殊情况!
sum=;
}
printf("%.1lf\n",sum);
return ;
}
PAT 甲级 1017 Queueing at Bank (25 分)(模拟题,有点思维小技巧,第二次做才理清思路)的更多相关文章
- PAT甲级1017. Queueing at Bank
PAT甲级1017. Queueing at Bank 题意: 假设一家银行有K台开放服务.窗前有一条黄线,将等候区分为两部分.所有的客户都必须在黄线后面排队,直到他/她轮到服务,并有一个可用的窗口. ...
- 【PAT甲级】1017 Queueing at Bank (25 分)
题意: 输入两个正整数N,K(N<=10000,k<=100)分别表示用户的数量以及银行柜台的数量,接下来N行输入一个字符串(格式为HH:MM:SS)和一个正整数,分别表示一位用户到达银行 ...
- PAT 甲级 1017 Queueing at Bank
https://pintia.cn/problem-sets/994805342720868352/problems/994805491530579968 Suppose a bank has K w ...
- 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 ...
- PAT 甲级 1040 Longest Symmetric String (25 分)(字符串最长对称字串,遍历)
1040 Longest Symmetric String (25 分) Given a string, you are supposed to output the length of the ...
- PAT 甲级 1083 List Grades (25 分)
1083 List Grades (25 分) Given a list of N student records with name, ID and grade. You are supposed ...
- PAT甲级——1130 Infix Expression (25 分)
1130 Infix Expression (25 分)(找规律.中序遍历) 我是先在CSDN上面发表的这篇文章https://blog.csdn.net/weixin_44385565/articl ...
- PAT 甲级 1074 Reversing Linked List (25 分)(链表部分逆置,结合使用双端队列和栈,其实使用vector更简单呐)
1074 Reversing Linked List (25 分) Given a constant K and a singly linked list L, you are supposed ...
- PAT 甲级 1086 Tree Traversals Again (25分)(先序中序链表建树,求后序)***重点复习
1086 Tree Traversals Again (25分) An inorder binary tree traversal can be implemented in a non-recu ...
随机推荐
- linux 终端命令学习
Linux 的版本不同,其终端下命令也有所差异的. cal -y / -d /-m 查看日历的 free -m /df -m 查剩余空间的 passwd -l / -u 用户名 -锁定,解锁 ...
- Ubuntu系统---C++之Eclipse编译器 CDT插件安装
Ubuntu系统---Ecli ...
- Java字节码方法表与属性表详解
继续跟着上一次[https://www.cnblogs.com/webor2006/p/9502507.html]的那10个代表code的字节分析,如下: 而这些字节其实对应的信息是它: 所以问题就来 ...
- 2019牛客多校第三场D BigInteger——基础数论
题意: 用 $A(n)$ 表示第 $n$ 个只由1组成分整数,现给定一个素数 $p$,求满足 $1 \leq i\leq n, 1 \leq j \leq m, A(i^j) \equiv 0(mo ...
- 第八章 用SQL语句操作数据
--切换数据库:手动切换和命令切换 use MySchool --向Student表中插入数据 --语法:INSERT [INTO] 表名 (列名) VALUES (值列表) --注意事项: --1. ...
- 五十一.Openstack概述 部署安装环境 、 部署Openstack OpenStack操作基础
虚拟化技术的底层构成: 内核的虚拟化模块(KVM):从内核集去提供虚拟化及CPU指令集的支持,要求CPU支持,(CPU有VMX指令集) 硬件仿真层(QEMU):虚拟一些周边设备,鼠标.键盘.网卡. ...
- Shell 05 Sed
一.基本用方法 1.sed文本处理工具的用法 用法1:前置命令 | sed [选项] '条件指令' 用法2:sed [选项] '条件指令' 文件.. .. 注意:没有条件时候,默认所有条件, ...
- decompiler
.NET Reflector trial version http://www.red-gate.com/products/dotnet-development/reflector/ 破解版本 .N ...
- Gym - 101955K Let the Flames Begin 约瑟夫环
Gym - 101955KLet the Flames Begin 说实话,没怎么搞懂,直接挂两博客. 小飞_Xiaofei的约瑟夫问题(Josephus Problem)3:谁最后一个出列 小飞_ ...
- CSP-S模拟68 题解
T1: 不难想到贪心,但是怎么贪,他有两个限制条件,所以不是很好搞,所以用一个类似与wqs二分的思路我可能在口胡,因为你肯定要把最小的给删掉,所以你限定一个x或y,然后在选出另一个限制,所以要同时维护 ...