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 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)的更多相关文章

  1. PAT1017:Queueing at Bank

    1017. Queueing at Bank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Supp ...

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

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

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

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

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

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

  8. PAT (Advanced Level) 1017. Queueing at Bank (25)

    简单模拟. #include<iostream> #include<cstring> #include<cmath> #include<algorithm&g ...

  9. PAT甲题题解-1017. Queueing at Bank (25)-模拟

    有n个客户和k个窗口,给出n个客户的到达时间和需要的时长有空闲的窗口就去办理,没有的话就需要等待,求客户的平均时长.如果在8点前来的,就需要等到8点.如果17点以后来的,则不会被服务,无需考虑. 按客 ...

随机推荐

  1. metasploit 读书笔记-EXPLOITATION

    一、渗透攻击基础 1.常用命令 show exploits 显示Meta框架中所有可用的渗透攻击模块。 show options 显示模块所需要的各种参数 back 返回Meta的上一个状态 sear ...

  2. 割点(Tarjan算法)【转载】

    本文转自:www.cnblogs.com/collectionne/p/6847240.html 供大家学习 前言:之前翻译过一篇英文的关于割点的文章(英文原文.翻译),但是自己还有一些不明白的地方, ...

  3. 微信小程序小结(4) -- 分包加载及小程序间跳转

    分包加载 某些情况下,开发者需要将小程序划分成不同的子包,在构建时打包成不同的分包,用户在使用时按需进行加载(主要是空间不够用,哈哈~). 在构建小程序分包项目时,构建会输出一个或多个功能的分包,其中 ...

  4. Js判断参数(String,Array,Object)是否为undefined或者值为空

    在一些前端控件要提交数据到服务器端的数据验证过程中,需要判断提交的数据是否为空.如果是普通表单的字符串数据,只需要在 trim 后判断 length 即可,而这里需要的数据可以是各种不同的类型,通过 ...

  5. kuangbin专题16B(kmp模板)

    题目链接: https://vjudge.net/contest/70325#problem/B 题意: 输出模式串在主串中出现的次数 思路: kmp模板 在 kmp 函数中匹配成功计数加一, 再令 ...

  6. 缩点+spfa最长路【bzoj】 1179: [Apio2009]Atm

    [bzoj] 1179: [Apio2009]Atm Description Siruseri 城中的道路都是单向的.不同的道路由路口连接.按照法律的规定, 在每个路口都设立了一个 Siruseri ...

  7. Python数组(一)

    一.索引 数组中的索引(下标)是从0开始递增的,你可以像下面这样使用编号来访问各个元素: test=['java','C#','C++','html','Spring'] print(test[0]) ...

  8. 数据结构28:广义表及M元多项式

    广义表,又称为列表.记作: LS = (a1,a2,…,an) ;( LS 为广义表的名称, an 表示广义表中的数据). 广义表可以看作是线性表的推广.两者区别是:线性表中的数据元素只能表示单个数据 ...

  9. asp.net mvc 中的 controller和asp.net web api 的apicontroller有什么区别?(转)

    本质上区别不大,一个返回html/text类型的response,一个返回json/text或者xml/text类型的response,对于api环境而言,apicontroller更智能一点,他可以 ...

  10. 3.Best Time to Buy and Sell Stock(买卖股票)

    Level: ​ ​ Easy 题目描述: Say you have an array for which the ith element is the price of a given stock ...