• 1017 Queueing at Bank


    1017 Queueing at Bank

    0、题目

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

    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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    Sample Output:

    8.2
    
    • 1

    1、大致题意

    类似于 1014 Waiting in Line ,给出银行窗口数和办理业务人头数,并给出这些人到达的时间,计算最后人们的平均等待时间。

    1.1 测试点5

    有了 1014 Waiting in Line 作为铺垫,基本上坑点都一模一样,就是 17:00 及以前来的那批到 17:00 时还没被服务的人,哪怕过了 17:00 也会被继续服务,哪怕银行加班到凌晨也要处理这批人的业务(诶,这真的反常识啊)。

    这个坑点被设计为 测试点5

    在这里插入图片描述

    2、基本思路

    设计结构体 customercounter ,然后 sort 大法排序顾客到达店的顺序。用一个 priority_queue 模拟柜台。

    struct customer {
    	int hh,mm,ss,time; //time为转化为秒以后的时间
    	int cost; //办理业务所需时间
    	int start; //开始办理时间
    	bool operator >(const customer &a)const {
    		if(time!=a.time) {
    			return time < a.time;
    		} else {
    			return cost < a.cost;
    		}
    	}
    };
    
    struct counter {
    	int id;
    	int end;
    	bool operator >(const counter &a)const {
    		if(end!=a.end) {
    			return end > a.end;
    		} else {
    			return id > a.id;
    		}
    	}
    };
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24

    3、AC代码

    #include
    #include
    #include
    using namespace std;
    
    struct customer {
    	int hh,mm,ss,time; //time为转化为秒以后的时间
    	int cost; //办理业务所需时间
    	int start; //开始办理时间
    	bool operator >(const customer &a)const {
    		if(time!=a.time) {
    			return time < a.time;
    		} else {
    			return cost < a.cost;
    		}
    	}
    } cus[10005];
    
    struct counter {
    	int id;
    	int end;
    	bool operator >(const counter &a)const {
    		if(end!=a.end) {
    			return end > a.end;
    		} else {
    			return id > a.id;
    		}
    	}
    } cou[105],tmp;
    int n,k,ans;
    priority_queue<counter,vector<counter>,greater<counter> >q1;
    
    int toTime(int hh,int mm,int ss) {
    	return hh*60*60+mm*60+ss;
    }
    
    int main() {
    	cin>>n>>k;
    	for(int i=1; i<=n; i++) {
    		scanf("%d:%d:%d %d",&cus[i].hh,&cus[i].mm,&cus[i].ss,&cus[i].cost);
    		cus[i].cost*=60;
    		cus[i].time=toTime(cus[i].hh,cus[i].mm,cus[i].ss);
    	}
    	sort(cus+1,cus+n+1,greater<customer>());
    //	cout<
    	ans=1;
    	for(int i=1; i<=k; i++) {
    		if(ans>n) {
    			break;
    		} else {
    			tmp.id=i;
    			if(cus[ans].time<=8*60*60) {
    				cus[ans].start=8*60*60;
    			} else {
    				cus[ans].start=cus[ans].time;
    			}
    			tmp.end=cus[ans].start+cus[ans].cost;
    			q1.push(tmp);
    			ans++;
    		}
    	}
    	while(!q1.empty()&&ans<=n) {
    		tmp=q1.top();
    		q1.pop();
    		if(cus[ans].time>=tmp.end){
    			cus[ans].start=cus[ans].time;
    		}else{
    			cus[ans].start=tmp.end;
    		}
    		tmp.end=cus[ans].start+cus[ans].cost;
    		q1.push(tmp);
    		ans++;
    	}
    	int summ=0,num=0;
    	for(int i=1; i<=n; i++) {
    		if(cus[i].time>17*60*60) { //坑点!!17:00到的不接待
    			continue;
    		} else {
    			num++;
    			summ+=(cus[i].start-cus[i].time);
    		}
    	}
    	printf("%.1f\n",summ/num/60.0);
    	return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85

    在这里插入图片描述

  • 相关阅读:
    【JavaSE专栏55】Java集合类HashTable解析,基于哈希表实现的唯一性键值对存储数据结构
    PyTorch中grid_sample的使用方法
    AI中文版怎么用,版本分享,GPT官网入口
    国际版腾讯云/阿里云:全站加快有哪些功用?有哪些优势?适用于什么场景?
    js制作选项卡:实现点击选项卡会跳转到相应的页面
    小程序实现sql插入语句转换成Laravel迁移语句
    力扣sql
    架构思考 (五)
    面试:ThreadLocal
    spring ioc
  • 原文地址:https://blog.csdn.net/qq_46371399/article/details/126376205