1017. Queueing at Bank (25)
来源:互联网 发布:少儿编程课程要会什么 编辑:程序博客网 时间:2024/06/13 19:09
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<iostream>#include<algorithm>#include<string>#include<vector>using namespace std;int n,k;struct node{ int wait; int time; node(){} node(int h,int m,int s,int w){ time=h*60*60+m*60+s; wait=w; }};vector<node> user;vector<node> wait;bool cmp(node a,node b){ return a.time<b.time;}int main(){ scanf("%d%d",&n,&k); node a; a.time=8*60*60,a.wait=0; for(int i=0;i<k;i++){ wait.push_back(a); } for(int i=0;i<n;i++){ int h,m,s,w; scanf("%d:%d:%d%d",&h,&m,&s,&w); node temp=node(h,m,s,w); if(temp.time<=17*60*60) user.push_back(temp); } sort(user.begin(),user.end(),cmp); float ans=0; for(int i=0;i<user.size();i++){ if(wait[0].time<=user[i].time){ wait[0].time=user[i].time+user[i].wait*60; } else{ ans+=wait[0].time-user[i].time; wait[0].time=wait[0].time+user[i].wait*60; } sort(wait.begin(),wait.begin()+k,cmp); } ans/=user.size(); float mm=int(ans-int(ans)%60)/60; float ss=(ans-mm*60)/60; mm+=ss; printf("%.1f",mm); return 0;}
- 1017. Queueing at Bank (25)
- 1017. Queueing at Bank (25)
- 1017. Queueing at Bank (25)
- 1017. Queueing at Bank (25)
- 1017. Queueing at Bank (25)
- 1017. Queueing at Bank (25)
- 1017. Queueing at Bank (25)
- 1017. Queueing at Bank (25)
- 1017. Queueing at Bank (25)
- 1017. Queueing at Bank (25)
- 1017. Queueing at Bank (25)
- 1017. Queueing at Bank (25)
- 1017. Queueing at Bank (25)
- 1017. Queueing at Bank (25)
- 1017. Queueing at Bank (25)
- 1017. Queueing at Bank (25)
- 1017. Queueing at Bank (25)
- 1017. Queueing at Bank (25)
- iOS-项目中的知识点总结
- 开源 Swift AutoLayout 框架 SnapKit 介绍
- unity2d角色防止二段跳解决方案
- 我的第一条程序"世界你好"
- Linux精讲——软链接和硬链接
- 1017. Queueing at Bank (25)
- 整理:统计学习-1
- POJ 3074 Sudoku(DLX+精确覆盖)
- Coderforces 629A Far Relative’s Birthday Cake 【水题】
- Unity3D 5 官方教程:SpeedTree/LOD Trees
- Asp.Net MVC 使用FileResult导出Excel数据文件
- POJ 2488 A Knight's Journey 搜索
- 数组(Array)那点事
- TCP协议的三次握手和四次挥手