1026. Table Tennis (30)

#include <iostream>
#include <cstdio>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;

#define K 101

struct customer {
	int ct;
	int pt;
	int vip;
	
	bool operator<(const customer &b) const {
		return ct < b.ct;
	}
};

struct leave {
	int time;
	int table;
	
	leave(int time = 0, int table = 0) {
		this->time = time;
		this->table = table;
	}
	
	bool operator<(const leave &b) const {
		return time > b.time;
	}
};

void printservice(int ct, int st) {
	printf("%02d:%02d:%02d %02d:%02d:%02d %.0lf\n",
		ct/3600, ct/60%60, ct%60,
		st/3600, st/60%60, st%60,
		(st-ct+1)/60.0);
}

void welcome(customer &c, bool tf[], int sn[], int lt[], int &rvt, int &rnvt,
	deque<customer> &vq, deque<customer> &nvq, priority_queue<leave> &lq) {
	
	if(c.vip) {
		if(rvt || rnvt) {
			int table;
			if(rvt) {
				for(table = 1; !tf[table] || lt[table] >= c.ct; table ++) ;
				rvt --;
			}
			else {
				for(table = 1; lt[table] >= c.ct; table ++) ;
				rnvt --;
			}
			
			sn[table] ++;
			lt[table] = c.ct + c.pt*60;
			lq.push(leave(lt[table], table));
			
			printservice(c.ct, c.ct);
		}
		else {
			vq.push_back(c);
		}
	}
	else {
		if(rnvt || rvt) {
			int table;
			for(table = 1; lt[table] >= c.ct; table ++) ;
			if(tf[table])
				rvt --;
			else
				rnvt --;
			/*if(rnvt) {
				for(table = 1; lt[table] >= c.ct || tf[table]; table ++) ;
				rnvt --;
			}
			else {
				for(table = 1; lt[table] >= c.ct; table ++) ;
				rvt --;
			}*/
			
			sn[table] ++;
			lt[table] = c.ct + c.pt*60;
			lq.push(leave(lt[table], table));
			
			printservice(c.ct, c.ct);
		}
		else {
			nvq.push_back(c);
		}
	}
}

void satisfy(int now, bool tf[], int sn[], int lt[], int &rvt, int &rnvt,
	deque<customer> &vq, deque<customer> &nvq, priority_queue<leave> &lq) {
	
	while((vq.size() || nvq.size()) && (rvt || rnvt)) {
		customer c = {};
		int table;
		if(rvt && !rnvt) {
			if(vq.size()) {
				c = vq.front();
				vq.pop_front();
			}
			else {
				c = nvq.front();
				nvq.pop_front();
			}
			for(table = 1; lt[table] != now; table ++) ;
			rvt --;
		}
		else if(!rvt && rnvt) {
			if(vq.size() && nvq.empty()) {
				c = vq.front();
				vq.pop_front();
			}
			else if(vq.empty() && nvq.size()) {
				c = nvq.front();
				nvq.pop_front();
			}
			else {
				customer vc = vq.front();
				customer nvc = nvq.front();
				if(vc.ct < nvc.ct) {
					c = vc;
					vq.pop_front();
				}
				else {
					c = nvc;
					nvq.pop_front();
				}
			}
			for(table = 1; lt[table] != now; table ++) ;
			rnvt --;
		}
		else {
			if(vq.size() && nvq.empty()) {
				c = vq.front();
				vq.pop_front();
			}
			else if(vq.empty() && nvq.size()) {
				c = nvq.front();
				nvq.pop_front();
			}
			else {
				customer vc = vq.front();
				customer nvc = nvq.front();
				if(vc.ct < nvc.ct) {
					c = vc;
					vq.pop_front();
				}
				else {
					c = nvc;
					nvq.pop_front();
				}
			}
			if(c.vip) {
				for(table = 1; lt[table] != now || !tf[table]; table ++) ;
				rvt --;
			}
			else {
				if(vq.size()) {
					for(table = 1; lt[table] != now || tf[table]; table ++) ;
					rnvt --;
				}
				else {
					for(table = 1; lt[table] != now; table ++) ;
					if(tf[table])
						rvt --;
					else
						rnvt --;
				}
			}
		}
		
		sn[table] ++;
		lt[table] += (c.pt*60);
		lq.push(leave(lt[table], table));
		
		printservice(c.ct, now);
	}
}

int main(int argc, char **argv) {
	int n;
	cin >> n;
	deque<customer> in;
	for(int i = 0; i < n; i ++) {
		int h, m, s, pt, flag;
		scanf("%d:%d:%d %d %d", &h, &m, &s, &pt, &flag);
		if(pt > 120) 
			pt = 120;
		customer c = { h*3600 + m*60 + s, pt, flag };
		if(c.ct < 21*60*60)
			in.push_back(c);
	}
	sort(in.begin(), in.end());
	
	int k, m;
	cin >> k >> m;
	bool tf[K] = {};
	for(int i = 0; i < m; i ++) {
		int table;
		cin >> table;
		tf[table] = true;
	}
	
	int rvt = m;
	int rnvt = k - m;
	
	int sn[K] = {};
	int lt[K] = {};
	
	deque<customer> nvq;
	deque<customer> vq;
	priority_queue<leave> lq;
	
	int now = 0;
	while((in.size() || lq.size()) && now < 21*60*60) {
		customer c;
		leave le;
		if(in.size() && lq.empty()) {
			c = in.front();
			in.pop_front();
			welcome(c, tf, sn, lt, rvt, rnvt, vq, nvq, lq);
		}
		if(in.empty() && lq.size()) {
			le = lq.top();
			now = le.time;
			if(now >= 21*60*60)
				continue;
			while(le.time == now) {
				lq.pop();
				if(tf[le.table])
					rvt ++;
				else
					rnvt ++;
				
				if(lq.size())
					le = lq.top();
				else
					break;
			}
			satisfy(now, tf, sn, lt, rvt, rnvt, vq, nvq, lq);
		}
		else {
			c = in.front();
			le = lq.top();
			if(le.time < c.ct || (le.time == c.ct && vq.empty() && nvq.empty())) {
				now = le.time;
				while(le.time == now) {
					lq.pop();
					if(tf[le.table])
						rvt ++;
					else
						rnvt ++;
					
					if(lq.size())
						le = lq.top();
					else
						break;
				}
				satisfy(now, tf, sn, lt, rvt, rnvt, vq, nvq, lq);
			}
			else {
				in.pop_front();
				welcome(c, tf, sn, lt, rvt, rnvt, vq, nvq, lq);
			}
		}
	}
	cout << sn[1];
	for(int i = 2; i <= k; i ++) {
		cout << ' ' << sn[i];
	}
	cout << endl;
	
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值