PAT (Advanced Level) Practice:1017 Queueing at Bank (25 分) 第5个测试点有错误

1017 Queueing at Bank (25 分) 第5个测试点有错误

错误情况分析


队伍只留下在17:00:00之前到达的顾客。在队伍中,如果最早空出来的窗口大于了17:00:00,平均等待时间如何计算?

测试点5默认的情况:继续把顾客的处理时间加上去,然后对窗口队列重新排队,直到所有顾客处理完毕。
正确情况:超过17:00:00之后,所有没排上的顾客结束服务。总时间=17:00:00-顾客来的时间。

代码

#include <iostream>
using namespace std;
#include <vector>
#include <algorithm>

class person
{
public:
	int come;
	int process;
};

bool cmp(person p1, person p2)
{
	return p1.come < p2.come;
}
int main()
{
	int n, k;
	cin >> n >> k;
	vector<person> persons;
	for (int i = 0; i < n; i++)
	{
		int hour, min, sec,t;
		scanf("%d:%d:%d %d", &hour, &min, &sec,&t);
		if (hour > 17||(hour==17&&min>0)||(hour==17&&sec>0))
			continue;
		person p;
		p.come = hour * 3600 + min * 60 + sec;
        if(t>60)
            t=60;
		p.process=t*60;
		persons.push_back(p);
	}
	
	sort(persons.begin(), persons.end(), cmp);
	vector<int> windows;
	for (int i = 0; i < k; i++)
	{
		windows.push_back(28800);
	}
	int sum = 0;
	for (int i = 0; i < persons.size(); i++)
	{
		sort(windows.begin(), windows.end());
		if (windows[0] > 61200)
		{
		    //sum += 61200 - persons[i].come;//这才是正确的情况
            sum+=windows[0]-persons[i].come;//测试点5的
            windows[0]+=persons[i].process;//错误情况
		}
		else
		{
			if (persons[i].come < windows[0])
			{
				sum += windows[0]-persons[i].come;
				windows[0] += persons[i].process;
			}
			else
			{
				windows[0] =persons[i].come + persons[i].process;
			}
		}
	}
	double res = sum * 1.0 / (persons.size() * 60);
	printf("%.1f", res);
	return 0;
}
posted @ 2021-02-04 15:20  韩天尊  阅读(226)  评论(0)    收藏  举报