PAT甲级 1017 Queueing at Bank

原题传送门 >>>
几个注意点:

1、凡是在17:00:00之前(包括17:00:00)到的顾客,银行都必须把它们完全服务完成。(也就是说,在这之前银行不下班)。
这个设定也太迷惑了吧???

2、17:00:01之后到的顾客,不计入总人数,也没有排队时间。

参考代码:

#include<cstdio>
#include<map>
#include<cstring>
#include<algorithm>
using namespace std;

const int INF = 0x3f3f3f3f;
const int END_TIME = 17*3600;
typedef pair<int,int> P;

map<int,int> line;//抵达时间、所需时间 
int N,K;
int windows[102];//i号窗口顾客需要的时间,单位是秒 

int glTime = 0;//最多17*60*60, 单位为秒 
int wholeTime = 0;
int countCustomer = 0;

int init(){
	memset(windows,0,102*sizeof(int));
	scanf("%d%d",&N,&K);
	for(int i = 0; i < N; ++i){
		int h, m, s;
		scanf("%d:%d:%d",&h,&m,&s);
		int t;
		scanf("%d",&t);
		P tmp;
		tmp.first = h*3600 + m * 60 + s;
        if(tmp.first <= END_TIME) {++countCustomer;
		tmp.second = t*60;
		line.insert(tmp);
                      }
	}
    if(N < 1){
        printf("0.0\n");
    }
	glTime = 8 * 3600;
	return 0;
}
int forward(){
	int minTime = INF;
	for(int i = 0; i < K; ++i){
		if(windows[i] < minTime){
			minTime = windows[i];
		}
	}//找到窗口的最小时间minTime
	glTime += minTime;
	if(minTime > 0)
	{		
		for(int i = 0; i < K; ++i){
			windows[i] -= minTime;		
		}//所有窗口 减去minTime
	}
	
	if(glTime < line.begin()->first){//现在队头是空的,需要等待顾客到来 
		int waitForCustom = line.begin()->first - glTime;//等待顾客的时间 
		glTime = line.begin()->first;
		for(int i = 0; i < K; ++i){
			windows[i]-= waitForCustom;
			if(windows[i] < 0) windows[i] = 0;
		}
	}
	for(int i = 0; i < K; ++i){
			if(windows[i]==0){//空闲窗口,把队头元素塞进去
				if(glTime < line.begin()->first) break;
					wholeTime += (glTime - line.begin()->first);
					windows[i] = line.begin()->second;
					line.erase(line.begin());
					if(line.size() == 0){
						return -1;
					}
			}

	}
	return 0;
}

int solve(){
	init();
	while(forward()==0);
	printf("%.1lf\n",(double)wholeTime/countCustomer/60);
	return 0;
}

int main(){
	solve();
	return 0;
}
Queueing theory is a mathematical study of waiting lines or queues that arise in various real-life scenarios, such as customer service, traffic congestion, hospital emergency rooms, and telecommunications networks. Basic queueing theory involves the following concepts: 1. Arrival Process: This is the process of customers arriving at the queue. The arrival process can be modeled using different distributions, such as Poisson or exponential. 2. Service Process: This is the process of serving customers in the queue. The service process can also be modeled using different distributions, such as Poisson or exponential. 3. Queue Length: This is the number of customers waiting in the queue at any given time. 4. Queue Occupancy: This is the proportion of time that the server is busy serving customers. 5. System Capacity: This is the maximum number of customers that the system can handle at any given time. 6. Utilization: This is the proportion of time that the server is busy serving customers compared to the total time. 7. Waiting Time: This is the time that a customer spends waiting in the queue before being served. 8. Service Time: This is the time that a customer spends being served by the server. 9. Queueing Models: There are different queueing models that can be used to analyze queueing systems, such as the M/M/1 model, M/M/c model, M/G/1 model, and M/D/1 model. 10. Performance Measures: Different performance measures can be used to evaluate queueing systems, such as average waiting time, average queue length, and system throughput.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值