1014 Waiting in Line

这题有个狗屎一样的测试点(4、5),题目没有说明17:00之前进入窗口服务的顾客在超时情况下任然会得到完整服务,比如16:59进入服务窗口,服务一个小时,17:59结束服务,那么17:59就是结果而非Sorry。

#include<cstdio>
#include<string>
#include<queue>
#include<map>

using namespace std;

#pragma warning(disable:4996)

const int allTime = 9 * 60;

void MinutesToTime(int minutes) {
	//if (minutes > allTime)printf("Sorry\n");
	//else {
	int HH = 8 + minutes / 60;
	int MM = minutes % 60;
	printf("%02d:%02d\n", HH, MM);
	//}
	return;
}

struct customer {
	int time;
	int index;
	bool flag;
	customer() {}
	customer(int time_, int index_, bool flag_) {
		time = time_;
		index = index_;
		flag = flag_;
	}
};
const int maxn = 1010;
struct window {
	queue<customer*> customers;
}windows[maxn];


int N, M, K, Q;
queue<customer*> custs;
map<int, int> ans;

bool insert(customer* a) {
	int min = windows[0].customers.size(), which_window = 0;
	for (int i = 1; i < N; i++) {
		if (windows[i].customers.size() < min) {
			min = windows[i].customers.size();
			which_window = i;
		}
	}
	if (min >= M)return false;// is to delete end customer
	windows[which_window].customers.push(a);
	return true;
}

int time_now = 0;

int main() {
	scanf("%d %d %d %d", &N, &M, &K, &Q);
	if (N <= 0 || M <= 0) {
		for (int i = 0; i < Q; i++)printf("Sorry\n");
		return 0;
	}
	for (int i = 0; i < K; i++) {
		int time;
		scanf("%d", &time);
		customer *a = new customer(time, i + 1, false);
		custs.push(a);
	}

	int now = 0;
	while (now < allTime) {
		now++;
		while (custs.size() > 0 && insert(custs.front())) {
			custs.pop();
		}
		for (int i = 0; i < N; i++) {
			if (windows[i].customers.size() <= 0)continue;
			windows[i].customers.front()->time--;
			windows[i].customers.front()->flag = true;
			if (windows[i].customers.front()->time <= 0) {
				int index = windows[i].customers.front()->index;
				windows[i].customers.pop();
				ans[index] = now;
			}
		}

	}

	for (int i = 0; i < N; i++) {
		if (windows[i].customers.size() <= 0)continue;
		if (windows[i].customers.front()->flag) {
			now = allTime + windows[i].customers.front()->time;
			int index = windows[i].customers.front()->index;
			ans[index] = now;
		}
	}



	for (int i = 0; i < Q; i++) {
		int query = 0;
		scanf("%d", &query);
		if (ans.find(query) != ans.end()) {
			MinutesToTime(ans[query]);
		}
		else {
			printf("Sorry\n");
		}
	}

	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值