PAT 1014. Waiting in Line (30)

37 篇文章 0 订阅

//AC
//看了别人的代码,发现也并不是很复杂
//关键是要在入队时就把每个人的离开时间计算出来,这样方便多了
#include<iostream>
#include<queue>
#include<cstdio>
#define customer_max 1000+5

using namespace std;

queue<int> que[20 + 5];
int leavetime[customer_max] = { 0 };
int processtime[customer_max] = { 0 };
int cleartime[20 + 5] = { 0 };
int n, m, k, q;
int i = 0, j = 0;

int main(){
	cin >> n >> m >> k >> q;
	while (++i <= k)
		cin >> processtime[i];
	i = 1;
	int top = 1;
	for (; top <= k&&top <= m*n; top++){
		if (!i)	i += n;//窗口序号调整一下,从1-n
		que[i].push(top);
		leavetime[top] = cleartime[i] + processtime[top];
		cleartime[i] = leavetime[top];
		i = (i + 1) % n;
	}
	for (; top <= k; top++){
		//每一个客户要找队首客户leavetime最小的队列入队
		int min_time = leavetime[que[1].front()];
		int index = 1;
		for (i = 1; i <= n; i++){
			int first = que[i].front();
			if (min_time > leavetime[first]){
				min_time = leavetime[first];
				index = i;
			}
		}
		que[index].pop();
		que[index].push(top);
		leavetime[top] = cleartime[index] + processtime[top];
		cleartime[index] = leavetime[top];
	}
	while (q--){
		int tmp; cin >> tmp;
		if (leavetime[tmp] - processtime[tmp] >= 9 * 60)//注意等号,恰好在17:00轮到的客户是不能办理的
			printf("Sorry\n");
		else
			printf("%02d:%02d\n", leavetime[tmp] / 60 + 8, leavetime[tmp] % 60);
	}
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值