PAT (Advanced) 1014. Waiting in Line (30)

#include <iostream>
#include <vector>
#include <queue>

using namespace std;

const int INF = 0x6fffffff;

struct customer
{
	int process, leave;
}cus[1005];

int main()
{
	int n, m, k, q;
	cin >> n >> m >> k >> q;
	for (int i = 0; i < k; i++)
	{
		cin >> cus[i].process;
	}
	vector<queue<int>> winque(n);
	vector<int> end(n, 0);

	int i, j;
	for (i = 0; i < k && i < n * m; i++)
	{
		winque[i%n].push(i);
		cus[i].leave = end[i%n] + cus[i].process;
		end[i%n] = cus[i].leave;
	}
	int t, min, index, hh, mm;
	for (; i < k; i++)
	{
		min = INF;
		for (j = 0; j < n; j++)
		{
			t = winque[j].front();
			if (min > cus[t].leave)
			{
				min = cus[t].leave;
				index = j;
			}
		}
		cus[i].leave = end[index] + cus[i].process;
		end[index] = cus[i].leave;
		winque[index].pop();
		winque[index].push(i);
	}
	while (q--)
	{
		cin >> index;
		index--;
		if (cus[index].leave - cus[index].process < 540)
		{
			hh = cus[index].leave / 60 + 8;
			mm = cus[index].leave % 60;
			printf("%02d:%02d\n", hh, mm);
		}
		else
			printf("Sorry\n");
	}

}

你可能感兴趣的:(PAT (Advanced) 1014. Waiting in Line (30))