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 HHis 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 ...
随机推荐
- haproxy??
HAProxy是一个使用C语言编写的自由及开放源代码软件,其提供高可用性.负载均衡,以及基于TCP和HTTP的应用程序代理. HAProxy特别适用于那些负载特大的web站点,这些站点通常又需要会话保 ...
- Linux中找回误删除的文件
Linux中找回误删除的文件 作为一个多用户.多任务的Linux操作系统,会出现在没有备份的情况下将一些用户文件误删的情况,Linux下的文件一旦被删除,是难以恢复的.尽管删除命令只是在文件节点中作删 ...
- 《构建之法》——Alpha2项目的测试
这个作业属于哪个课程 课程的链接 这个作业要求在哪里 作业要求的链接 团队名称 Runningman 这个作业的目标 测试其他组的项目,互相借鉴 作业正文 作业正文 测试人姓名 陈嘉莹 测试人学号 2 ...
- php高精度计算
- Java&Selenium数据驱动【DataProvider+TestNG+Mysql】
Java&Selenium数据驱动[DataProvider+TestNG+Mysql] package testNGWithDataDriven; import java.io.IOExce ...
- tp5 左连接
db('detainform')->alias('d')->join("information i",'i.z_id=d.z_id','LEFT')->where ...
- TCP的三次握手与四次挥手的理解
本文经过借鉴书籍资料.他人博客总结出的知识点,欢迎提问 序列号seq:占4个字节,用来标记数据段的顺序,TCP把连接中发送的所有数据字节都编上一个序号,第一个字节的编号由本地随机产生:给字节编上 ...
- FineAdmin.Mvc 使用ok-admin+ASP.NET MVC搭建的通用权限后台管理系统
FineAdmin.Mvc 介绍 使用ok-admin+ASP.NET MVC搭建的通用权限后台管理系统RightControl后台layui模板不太好看,换成ok-admin v2.0重写一遍.项目 ...
- struts2之使用oracle分页(10)
ToolsUtil //每页显示的记录数 public static final int NUM_PER_PAGE=5; /* * java.util.Date转java.sql.Date */ pu ...
- ITextSharp开源PDF处理库
1:官方完整开源项目 http://sourceforge.net/projects/itextsharp/ 2:使用NUGET :> install-package itextsharp