pat 1017

#include <stdio.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;

struct Customer
{
	int hours;
	int minutes;
	int seconds;
	int process;
	int totalTime;
} ctm[10010];

struct Window
{
	int time; 
	Customer ctm;
};

queue<Window> window[110];

int n, K, num;

int TT = 8 * 60 * 60;

bool cmp(Customer a, Customer b)
{
	return a.totalTime < b.totalTime;
}

int timeWait[10010];

int main()
{
	int i, count, j;

	while(scanf("%d %d", &n, &K) != EOF)
	{
		memset(timeWait, 0, sizeof(timeWait));

		for(i = 0; i < n; i++)
		{
			scanf("%d:%d:%d %d", &ctm[i].hours, &ctm[i].minutes, &ctm[i].seconds, &ctm[i].process);
			ctm[i].totalTime = ctm[i].hours * 60 * 60 + ctm[i].minutes * 60 + ctm[i].seconds;
			if(ctm[i].process > 60)
				ctm[i].process = 60;
		}

		sort(ctm, ctm + n, cmp);

		count = 0;
		num = 0;
		Window wd, tmp;

		for(i = 0; i < K; i++)
		{
			wd.ctm = ctm[i];
			
			if(ctm[i].totalTime < TT)
			{
				wd.time = TT + ctm[i].process * 60;
			}
			else
				wd.time = ctm[i].process * 60 + ctm[i].totalTime;

			timeWait[i] = wd.time - ctm[i].totalTime - ctm[i].process * 60;
			num = i;
			window[i+1].push(wd);
		}
		
		for(; i < n; i++)
		{
			wd = window[1].front();
			int min = wd.time, index = 1;

			for(j = 2; j <= K; j++)
			{
				wd = window[j].front();
				if(wd.time < min)
				{
					min = wd.time;
					index = j;
				}
			}

			if(ctm[i].totalTime <= 17 * 60 * 60)
			{
				tmp.ctm = ctm[i];
				wd = window[index].front();
				window[index].pop();
				if(wd.time > ctm[i].totalTime) //之前一直有个case过不了,发现题目意思理解错了。即,客户只要在17:00之前到达银行,那么即使窗口的结束时间在17:00以后,那银行还是需要给客户服务的
					tmp.time = wd.time + ctm[i].process * 60;
				else if(ctm[i].totalTime >= wd.time)
					tmp.time = ctm[i].totalTime + ctm[i].process * 60;
				window[index].push(tmp);
				timeWait[i] = tmp.time - ctm[i].totalTime - ctm[i].process * 60;
				num = i;
			}
		}

		for(i= 0; i < n; i++)
			count += timeWait[i];
		
	printf("%.1lf\n", 1.0*count/60.0/(num+1));
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值