A1026 Table Tennis (30point(s))
花了好长时间都没ac,还差第五个测试点通不过,没办法了,先放着。
题意
优先安排id小的桌子。注意如果vip到了,优先安排vip桌子;
vip可以插队安排vip桌子,排队等待过程中如果有vip桌子空了优先安排正在等待的vip客户。
思路
用vis表示该用户是否已经被安排了。
总结
很难的模拟题。
Sample input:
9
20:52:00 10 0
08:00:00 20 0
08:02:00 30 0
20:51:00 10 0
08:10:00 5 0
08:12:00 10 1
20:50:00 10 0
08:01:30 15 1
20:53:00 10 1
3 1
2
Sample Output:
08:00:00 08:00:00 0
08:01:30 08:01:30 0
08:02:00 08:02:00 0
08:12:00 08:16:30 5
08:10:00 08:20:00 10
20:50:00 20:50:00 0
20:51:00 20:51:00 0
20:52:00 20:52:00 0
3 3 2
#include"bits/stdc++.h"
using namespace std;
struct Table{
int ss, isVip, cnt;
};
struct Node{
int ss,c,isVip,wait,vis;
};
void prin(int s){
int hh = s/3600;
int mm = s%3600/60;
int ss = s%60;
printf("%02d:%02d:%02d ",hh,mm,ss);
}
void dispatch(Table *t,Node *node){
t->ss = max(t->ss,node->ss);
node->vis = 1;
node->wait = t->ss - node->ss;
t->ss += node->c;
t->cnt ++;
}
int main(){
freopen("input.txt","r",stdin);
const int startTime = 8*3600;
const int closeTime = 21*3600;
int n,m,k;
cin >> n;
vector<Node*> nodes(n),vips;
for(int i=0;i<n;i++){
int hh,mm,ss; scanf("%d:%d:%d",&hh,&mm,&ss);
int cost_mm,isVip; scanf("%d%d",&cost_mm,&isVip);
Node *p = new Node{hh*3600+mm*60+ss,cost_mm*60,isVip,0,0};
nodes[i] = p;
if(isVip) vips.push_back(p);
}
sort(nodes.begin(),nodes.end(),[](Node *p1,Node *p2){
return p1->ss > p2->ss;
});
vector<Node*> ans = nodes;
sort(vips.begin(),vips.end(),[](Node *p1,Node *p2){
return p1->ss > p2->ss;
});
cin >> k >> m;
vector<Table> tables(k+1);
vector<int> vipTableIds(m);
for(int i=1;i<=k;i++) tables[i].ss = startTime;
for(int i=0;i<m;i++){
int id; scanf("%d",&id);
tables[id].isVip = 1;
vipTableIds[i] = id;
}
while(!nodes.empty()){
while(!nodes.empty() && nodes.back()->vis) nodes.pop_back();
while(!vips.empty() && vips.back()->vis) vips.pop_back();
if(nodes.empty() || nodes.back()->ss >= closeTime)
break;
Node *node = nodes.back();
if(node->isVip){
for(int id:vipTableIds){
if(tables[id].ss <= node->ss){
dispatch(&tables[id],node);
break;
}
}
}
if(node->vis) continue;
for(int i=1;i<=k;i++){
if(tables[i].ss <= node->ss){
dispatch(&tables[i],node);
break;
}
}
if(node->vis) continue;
Table *table = nullptr; int ss_min = INT32_MAX;
for(int i=1;i<=k;i++){
Table &t = tables[i];
if(t.ss < ss_min){
ss_min = t.ss;
table = &t;
}
}
if(table->ss >= closeTime)
break;
Node *vipNode = nullptr;
if(!vips.empty())
vipNode = vips.back();
if(vipNode != nullptr && table->isVip && vipNode->ss <= table->ss){
dispatch(table,vipNode);
continue;
}
dispatch(table,node);
}
sort(ans.begin(),ans.end(),[](Node *p1,Node *p2){
return p1->ss+p1->wait < p2->ss+p2->wait;
});
for(Node *p:ans){
if(!p->vis) continue;
prin(p->ss);
prin(p->ss + p->wait);
int mm = round((p->wait)/60.0);
printf("%d\n",mm);
}
for(int i=1;i<=k;i++) {
if(i != k) printf("%d ",tables[i].cnt);
else printf("%d\n",tables[i].cnt);
}
}