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点以后来的,则不会被服务,无需考虑. 按客 ...
随机推荐
- onmouseover和onmouseout在GridView中应用 Ver2
第一个版本,可以参考:http://www.cnblogs.com/insus/archive/2009/03/13/1411057.html 以前的版本,是在Gridview的OnRowCreate ...
- nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx//conf/nginx.conf:117
SSL相关的配置加到了nginx的配置文件中后,nginx竟然启动不起来了 于是用如下命令测试问题所在: /usr/local/nginx/sbin/nginx -c /usr/local/nginx ...
- php二维数组的某一字段 做分组统计
$country=array_column($order,'country');$countryGP=array_count_values($country);对二维数组的某一字段 做分组统计
- Java框架之搭建环境maven报错
*maven Dependencies 中的地址通过POM 才会增加 正确是 1. m2所在位置 遇到的问题: java.lang.ClassNotFoundException: org.spring ...
- UVa_Live 3664(精度坑)
题意很好理解的贪心题,然而却卡疯了的精度坑. 再次理解一下double小数运算时可能导致的精度问题,本题为避免该问题可以将小数乘以100化为整数进行比较,输出的时候再除以100就ok: 思路也很好想, ...
- P2770 航空路线问题
\(\color{#0066ff}{题目描述}\) 给定一张航空图,图中顶点代表城市,边代表 2 城市间的直通航线.现要求找出一条满足下述限制条件的且途经城市最多的旅行路线. (1)从最西端城市出发, ...
- P4015 运输问题
\(\color{#0066ff}{题目描述}\) W 公司有 m 个仓库和 n 个零售商店.第 i 个仓库有 \(a_i\) 个单位的货物:第 j 个零售商店需要 \(b_j\) 个单位的货物. 货 ...
- idea 新建maven项目没有src及其子目录问题
注意在这一步中,填写maven的本地地址还有手动修改settings地址非常重要!!! 如果你是第一次配置maven,少配置任何一个将导致你以后建立的mvn项目全部没有src目录!!! 解决办法就是卸 ...
- 6.动态sql - if
满足条件的数据 mapper.xml 满足if条件就执行,不满足就不加 <select id="selectStateByTitle" parameterType=" ...
- #333 Div2 Problem B Approximating a Constant Range(尺取法)
题目:http://codeforces.com/contest/602/problem/B 题意 :给出一个含有 n 个数的区间,要求找出一个最大的连续子区间使得这个子区间的最大值和最小值的差值不超 ...