-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStall Reservations.cpp
More file actions
71 lines (62 loc) · 1.23 KB
/
Stall Reservations.cpp
File metadata and controls
71 lines (62 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <string.h>
#include <assert.h>
#include <queue>
#include <vector>
#include<list>
#include <algorithm>
#include<iostream>
#include<math.h>
using namespace std;
#define N 50005
#define Inf 0x3f3f3f3f
struct node{
int s; //活动的开始时间
int e; //活动的结束时间
int ind; //牛分配的牛棚号
int l; //牛的序号
friend bool operator>(node a,node b){
return a.e>b.e; //优先队列 按牛棚的结束时间排序
}
}g[N];
bool cmp(node a,node b){
return a.s<b.s; //按开始时间排序
}
bool cmp2(node a,node b){
return a.l<b.l; //按牛的序号排序
}
int main() {
int n;
while(cin>>n){
memset(g,0,sizeof(g));
for(int i=0;i<n;i++){
scanf("%d%d",&g[i].s,&g[i].e);
g[i].l = i;
}
sort(g,g+n,cmp);
priority_queue<node,vector<node>,greater<node> > q;
g[0].ind = 1;
q.push(g[0]);
int total = 1;
for(int i=1;i<n;i++){
node b = q.top();
if(g[i].s<=b.e){
total++;
g[i].ind = total;
q.push(g[i]);
}else{
q.pop();
g[i].ind = b.ind;
q.push(g[i]);
}
}
cout<<total<<endl;
sort(g,g+n,cmp2);
for(int i=0;i<n;i++){
cout<<g[i].ind<<endl;
}
}
return 0;
}