pat1017. 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 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 (<=10000) - 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<set>
#include<map>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<queue>
#include<vector>
#include<cmath>
using namespace std;
#define open 28800
#define close 61200
struct custom{
int come,cost,finish;
};
void swap(custom &a,custom &b){
custom c=a;
a=b;
b=c;
}
void BuildHeap(custom *cc,int m){
int fa,child=m-,i;
for(i=(child-)/;i>=;i--){
child=i*+;//左儿子
for(fa=i;child<m;child=fa*+){
if(child+<m&&cc[child].finish>cc[child+].finish){
child++;
}
if(cc[child].finish<cc[fa].finish){
swap(cc[fa],cc[child]);
fa=child;
}
else{
break;
}
}
}
}
void Insertion(custom *cc,custom cur,int &m){
int i=m++;
for(;i>&&cc[(i-)/].finish>cur.finish;i=(i-)/){
cc[i]=cc[(i-)/];
}
cc[i]=cur;
}
custom DeleteMin(custom *cc,int &m){
custom cur=cc[];
custom temp=cc[--m];
int fa,child=;
for(fa=;child<m;child=fa*+){
if(child<m-&&cc[child].finish>cc[child+].finish){
child++;
}
if(cc[child].finish<temp.finish){
cc[fa]=cc[child];
fa=child;//保证fa指向当前要比较的节点
}
else{
break;
}
}
cc[fa]=temp;
return cur;
}
bool cmp(custom a,custom b){
return a.come<b.come;
}
int main(){
//freopen("D:\\input.txt","r",stdin);
int n,nn;
int i,j;
scanf("%d %d",&n,&nn); //cout<<n<<" "<<nn<<endl; custom *c=new custom[n+],*cc=new custom[nn+];
int h,m,s,cost;
for(i=;i<n;i++){
scanf("%d:%d:%d %d",&h,&m,&s,&cost);
c[i].come=h*+m*+s;
c[i].cost=cost*;
}
int totaltime=,count=;
sort(c,c+n,cmp); j=;
for(i=;i<nn&&i<n;i++){
if(c[i].come<open){
totaltime+=open-c[i].come;
c[i].come=open;
}
if(c[i].come>close){
break;
}
c[i].finish=c[i].come+c[i].cost;
cc[i]=c[i];
count++;
} //cout<<count<<endl; if(count<nn){//人数不够
printf("%.1lf\n",totaltime*1.0//count);//不经意间看到,让我找了将近一小时!!
return ;
} BuildHeap(cc,count);//建堆 custom cur;
for(;i<n;i++){
cur=DeleteMin(cc,nn);
if(c[i].come<=close){//cur.finish<=close&&
if(cur.finish<c[i].come){
c[i].finish=c[i].come+c[i].cost;
}
else{
c[i].finish=cur.finish+c[i].cost;
totaltime+=cur.finish-c[i].come;
}
cur=c[i];
Insertion(cc,cur,nn);
count++;
}
else{
break;
}
}
printf("%.1lf\n",totaltime*1.0/count/);
return ;
}
pat1017. Queueing at Bank (25)的更多相关文章
- PAT1017:Queueing at Bank
1017. Queueing at Bank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Supp ...
- 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 ...
- 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 ...
- 1017. Queueing at Bank (25) - priority_queuet
题目如下: Suppose a bank has K windows open for service. There is a yellow line in front of the windows ...
- 1017 Queueing at Bank (25)(25 point(s))
problem Suppose a bank has K windows open for service. There is a yellow line in front of the window ...
- 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 ...
- 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 (Advanced Level) 1017. Queueing at Bank (25)
简单模拟. #include<iostream> #include<cstring> #include<cmath> #include<algorithm&g ...
- PAT甲题题解-1017. Queueing at Bank (25)-模拟
有n个客户和k个窗口,给出n个客户的到达时间和需要的时长有空闲的窗口就去办理,没有的话就需要等待,求客户的平均时长.如果在8点前来的,就需要等到8点.如果17点以后来的,则不会被服务,无需考虑. 按客 ...
随机推荐
- sql 脚本创建索引
之前从没有用SqlServer数据库处理过大数据量的表,都是用Oracle,然后一般为数据量较大的表添加索引或主键都是用plsql工具,今天正好需要为一张保存于SqlServer数据库的千万级数据表增 ...
- .Net Core下基于NPOI对Excel、Word操作封装
本库进行了重写,如果需要请转移到下文查看: https://www.cnblogs.com/holdengong/p/10889780.html 框架与依赖 框架:.NET Standard 2.0 ...
- 提取pfx证书公钥和私钥
从pfx提取密钥信息,并转换为key格式(pfx使用pkcs12模式补足) 1.提取密钥对(如果pfx证书已加密,会提示输入密码.) openssl pkcs12 -in 1.pfx -nocerts ...
- iOS工程师 - 简历
基本信息 姓 名:张学友 性 别:男 年 龄:28 学 历:本科 毕业学校:广西师范大学 专 业:通信工程 手 ...
- (multi)set的某些操作
(multi)set的某些操作 我们可以把multiset当作平衡树用~ 注意,必须定义小于运算符. s.begin() 返回指向第一个元素的迭代器. s.end() 返回指向最后元素的后面那个虚拟元 ...
- uoj#119. 【UR #8】决战圆锥曲线(线段树+复杂度分析)
题解 传送门 题解 然而要我来说我感觉只是个爆搜啊-- //minamoto #include<bits/stdc++.h> #define R register #define ll l ...
- v-touch使用方法以及在项目中遇到的问题
上篇博客中我记得还有一个坑没有解决好,在这篇博客中详细说明一下. 在 https://github.com/dreamITGirl/vuepageturn 我的这个代码库里,更新到2.1版本. 目前解 ...
- html之表单和简单CSS
一.==表单== 1. form表单本身 <form name="myform" action="#" method="get"> ...
- P2962 [USACO09NOV]灯Lights 对抗搜索
\(\color{#0066ff}{题目描述}\) 贝希和她的闺密们在她们的牛棚中玩游戏.但是天不从人愿,突然,牛棚的电源跳闸了,所有的灯都被关闭了.贝希是一个很胆小的女生,在伸手不见拇指的无尽的黑暗 ...
- git 本地分支与远程分支相关操作记录
1.远程分支中有新增分支,但自己的本地分支没有对应同步 git checkout -b [remote-branch-name] origin/[remote-branch-name] 2. 查看本地 ...