#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;
}
1026. Table Tennis (30)
最新推荐文章于 2021-05-30 16:11:45 发布