1017 Queueing at Bank
分数 25
作者 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.
Each input file contains one test case. For each case, the first line contains 2 numbers: N (≤104) - 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.
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.
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
8.2
敢情这个题是只要在17:00:00之前来到银行,就能够得到服务,不管在此之前已经
有了多少人了。
用优先队列存储每个窗口完成服务的时间(注意是完成),让时间越早完成,越先出队
进行服务下一个顾客;
/*
敢情这个题是只要在17:00:00之前来到银行,就能够得到服务,不管在此之前已经
有了多少人了。用优先队列存储每个窗口完成服务的时间(注意是完成),让时间越早完成,越先出队
进行服务下一个顾客;*/#include
#include
#include using namespace std;typedef long long LL;struct Infor
{string come;int ser;bool operator < (const Infor &a) const{return come < a.come;}
};const int N = 1e4+10;
struct Infor a[N];
int n, m;void Read()
{cin >> n >> m;for(int i=0; i> come >> ser;if(ser > 60)ser = 60;ser *= 60;a[i] = {come, ser};}
}int to_clock(string s)
{int c = 0;int h = stoi(s.substr(0, 2));int m = stoi(s.substr(3, 2));int sec = stoi(s.substr(6, 2));c = h * 3600 + m * 60 + sec;return c;
}double deal()
{double sum = 0;int cnt = 0;priority_queue, greater> pq;sort(a, a+n);LL ope = to_clock("08:00:00"), cls = to_clock("17:00:00");//窗口服务开始,给每个窗口安排一个顾客for(int i=0; i cls)break;if(t < ope){sum += ope - t;pq.push(ope+a[i].ser);}elsepq.push(t + a[i].ser);++cnt;}//窗口先完成服务先出队for(int i=m; i cls)break;if(t >= u)pq.push(t + a[i].ser);else{sum += u - t;pq.push(u + a[i].ser);}++cnt;}if(cnt == 0)return 0.0;return sum/ 60 / cnt;
}int main()
{Read();printf("%.1f\n",deal());return 0;
}