PAT (Advanced Level) 1014 Waiting in Line(模拟)

唯一坑点:并不是五点后结束的就Sorry,而是五点后开始的输出Sorry,即五点前开始,但是拖到五点后也会完成。没看清题目,查了半小时没找出错。。。

#include
#include
#include
#include
#include
#include
using namespace std;
int n, m, k, q;
struct People{
	int ptime,otime;
}people[1005];
int main(){
	scanf("%d%d%d%d",&n,&m,&k,&q);
	queue pq[20];
	for(int i = 0; i < k; i++){
		scanf("%d",&people[i].ptime);
	}
	for(int i = 0; i < k; i++){
		int mint = 1500, minq = 0, flag = 0, minsize = m+1, sizeq = 0;
		for(int j = 0; j < n; j++){
			if(pq[j].size() < m){
				if(minsize > pq[j].size()){
					minsize = pq[j].size();
					sizeq = j;
					flag = 1;
				}
			}
			else{
				if(mint > pq[j].front().otime){
					mint = pq[j].front().otime;
					minq = j;
				}
			}
		}
		if(flag == 0){
			pq[minq].pop();
			people[i].otime = pq[minq].back().otime+people[i].ptime;
			pq[minq].push(people[i]);
		}
		else{
			if(pq[sizeq].empty())
				people[i].otime = people[i].ptime;
			else
				people[i].otime = pq[sizeq].back().otime+people[i].ptime;
			pq[sizeq].push(people[i]);
		}
	}
	int qct;
	for(int i = 0; i < q; i++){
		scanf("%d",&qct);
		if(people[qct-1].otime-people[qct-1].ptime >= 540){
			printf("Sorry\n");
		}
		else{
			int h = people[qct-1].otime/60, m = people[qct-1].otime%60;
			printf("%02d:%02d\n",h+8,m);
		}
	}
	return 0;
}

 

你可能感兴趣的:(PAT)