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点以后来的,则不会被服务,无需考虑. 按客 ...
随机推荐
- Glib学习笔记(一)
你将学到什么 如何使用GObject实现一个新类 类头文件 声明一个类型的方法选择取决于类型是可被继承的还是不可被继承的. 不可被继承的类型(Final类型)使用G_DECLARE_FINAL_TYP ...
- QQ空间爬虫--获取好友信息
QQ空间网页版:https://user.qzone.qq.com/ 登陆后,进入设置,有一个权限设置,设置“谁能看我的空间”为好友可见,然后构造爬虫. (1)获取Cookie 两种方式: 第一种:通 ...
- 读《JavaScript权威指南》笔记(五)
1.getComputedStyle()方法的返回值是一个CSSStyleDeclaration对象,它代表了应用在指定元素(或伪对象)上的所有样式. 2.clip style="clip: ...
- [SinGuLaRiTy] 2017-07-22 NOIP2017 模拟赛
[SInGuLaRiTy-1029] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. <全是看看代码就会的水题,偷个懒不单独写题解了~& ...
- 文章推荐一个Java程序员跟大家谈谈从业心得
一个Java程序员跟大家谈谈从业心得 2017-10-21 java那些事 java那些事 java那些事 微信号 csh624366188 功能介绍 分享java开发中常用的技术,分享软件开发中各种 ...
- 转载 javaweb三大框架和MVC设计模式 (自己加拉些内容)
javaweb三大框架和MVC设计模式 一.MVC设计模式 1.MVC的概念 首先我们需要知道MVC模式并不是javaweb项目中独有的,MVC是一种软件工程中的一种软件架构模式,把软件系统分为三个基 ...
- codevs3027(dp)
题目链接: http://codevs.cn/problem/3027/ 题意: 中文题目诶~ 思路: dp 先给所有线段按照右端点值升序 sort 一下, 用 dp[i] 存储以第 i 条线段结尾的 ...
- 识别子串 (string)——后缀自动机+线段树
题目 [题目描述] 一般地,对于一个字符串 S,和 S 中第 $ i $ 个字符 x,定义子串 $ T=S(i.j) $ 为一个关于 x 的识别子申,当且仅当: 1.$ i \leq x \leq j ...
- P3240 [HNOI2015]实验比较 树形DP
\(\color{#0066ff}{ 题目描述 }\) 小D 被邀请到实验室,做一个跟图片质量评价相关的主观实验.实验用到的图片集一共有 \(N\) 张图片,编号为 \(1\) 到\(N\).实验分若 ...
- i++操作非原子的验证代码
package incre; public class Incre { public static void main(String[] args) { class Count implements ...