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. SQLite 如何清空表数据并将递增量归零

    SQLite并不支持TRUNCATE TABLE语句 方式一: DELETE FROM [Tab_User] --不能将递增数归零 方式二: DELETE FROM sqlite_sequence W ...

  2. C++: I/O流详解

    一.输入流操作 1.read 无格式输入指定字节数 istream& read ( char* pch, int nCount ); istream& read ( unsigned ...

  3. 洛谷P4137 Rmq Problem / mex(莫队)

    题目描述 有一个长度为n的数组{a1,a2,…,an}.m次询问,每次询问一个区间内最小没有出现过的自然数. 输入输出格式 输入格式: 第一行n,m. 第二行为n个数. 从第三行开始,每行一个询问l, ...

  4. vue file-loader vs url-loader

    1.前言 如果我们希望在页面引入图片(包括img的src和background的url).当我们基于webpack进行开发时,引入图片会遇到一些问题. 其中一个就是引用路径的问题.拿backgroun ...

  5. 使用Spring IOC容器引用外部属性文件

    一.引用外部属性文件 1.编写属性文件,以键值对形式存储,并放置在类路径(src)下 jdbc.jdbcUrl=jdbc:mysql://localhost:3306/BOOKSTORE?rewrit ...

  6. 《图解HTTP》阅读笔记--第四章--HTTP状态码

    第四章.返回结果的HTTP状态码前言:状态码的职责是告诉用户服务器端描述返回的请求,以便用户判断服务器处理是否正常. 状态码由三位数字和原因短语组成,其中三位数字的首位指定了响应类别:---1xx 接 ...

  7. GIS有关GP服务的发布和调用

    打印服务范例:http://blog.csdn.net/jingxinwjb/article/details/51906464 1.通过Modelbuilder新建工具.(注意:假如工具输出两个以上的 ...

  8. 黑马集合学习 自定义ArrayList01

    package demo; import java.util.Arrays; public class MyArrayList<T> { Object[] t; int size; pri ...

  9. Qt 学习之路 2(12):菜单栏、工具栏和状态栏

    Home / Qt 学习之路 2 / Qt 学习之路 2(12):菜单栏.工具栏和状态栏 Qt 学习之路 2(12):菜单栏.工具栏和状态栏  豆子  2012年9月10日  Qt 学习之路 2  2 ...

  10. 说Gradle

      说Gradle 刚开始认识Gradle这个名词是在蘑菇街的一场 交流会上,当时只是一个概念:第二面,是试图下载编译spring源码的时候:第三面,就是我司较真的安卓主程,有一天兴高彩烈的跟我说,我 ...