-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathair_conditioned_minions.cpp
106 lines (75 loc) · 1.99 KB
/
air_conditioned_minions.cpp
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <cstdio>
#include <cassert>
int main(){
struct node{
int min,max;
};
int n;
scanf("%d",&n);
node *all = new node[n];
int room = n;
for(int i = 0; i < n; i++){
scanf("%d %d", &all[i].min, &all[i].max);
}
for(int i = 0; i < n; i++){
for(int j = 0; j < (n - 1); j++){
if (all[j].min > all[j + 1].min){
node temp;
temp.min = all[j].min;
temp.max = all[j].max;
all[j] = all[j + 1];
all[j + 1] = temp;
}
}
}
for(int i = 0; i < n; i++){
int a = all[i].min;
int b = all[i].max;
for(int j = i + 1; j < n; j++){
int c = all[j].min;
int d = all[j].max;
if ((a <= c && c <= b)){
room--;
if (a < c){
all[j].min = a;
}
else if(a > c){
all[i].min = c;
a = c;
}
if(b > d){
all[i].max = d;
b = d;
}
else if(b < d){
all[j].max = b;
}
break;
}
else if ((a <= d && d <= b)){
room--;
if(b > d){
all[i].max = d;
b = d;
}
else if(b < d){
all[j].max = b;
}
if (a < c){
all[j].min = a;
}
else if(a > c){
all[i].min = c;
a = c;
}
break;
}
}
}
// for(int i = 0; i < n; i ++){
// printf("\n%d %d\n",all[i].min,all[i].max);
// }
delete [] all;
printf("%d\n",room);
return 0;
}