-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskyline.cpp
71 lines (71 loc) · 1.22 KB
/
skyline.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
#include<bits/stdc++.h>
#define inf 999999
using namespace std;
class point{
public:
double x;
double y;
};
void myMerge(point* pt,int lo,int hi);
bool acompare(point lhs, point rhs){
return lhs.x < rhs.x;
}
void comp(point* pt,int i,int j){
if(pt[i].x>=pt[j].x&&pt[i].y>=pt[j].y){
pt[i].x=inf;
pt[i].y=inf;
}
else if(pt[i].x<=pt[j].x&&pt[i].y<=pt[j].y){
pt[j].x=inf;
pt[j].y=inf;
}
}
void skyLine(point* pt,int lo,int hi){
if(lo==hi)
return;
else if(abs(hi-lo)==1){
comp(pt,lo,hi);
}
else{
int mid=(lo+hi)/2;
skyLine(pt,lo,mid);
skyLine(pt,mid+1,hi);
myMerge(pt,lo,hi);
}
}
void myMerge(point* pt,int lo,int hi){
int mid=(lo+hi)/2;
for(int i=0; i<=mid; i++){
for(int j=mid+1; j<=hi; j++){
comp(pt,i,j);
}
}
}
int main(){
int n;
cin>>n;
point pt[n];
for(int i=0; i<n; i++){
cin>>pt[i].x>>pt[i].y;
}
sort(pt,pt+n,acompare);
skyLine(pt,0,n-1);
cout<<"Skyline:"<<endl;
for(int i=0; i<n; i++){
if(pt[i].x!=inf)
cout<<pt[i].x<<" "<<pt[i].y<<endl;
}
return 0;
}
/*
Input:
8
1 11
2 6
3 13
12 7
14 3
19 18
23 13
24 4
*/