-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsweep line.cpp
More file actions
93 lines (63 loc) · 1.77 KB
/
sweep line.cpp
File metadata and controls
93 lines (63 loc) · 1.77 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <bits/stdc++.h>
using namespace std;
//funciona até N = 1000
#define N 1100
struct point{
int x,y;
};
struct event{
int i,t;
};
point rect[N][2];
bool usado[N*2];
bool comp_x(event ant,event dps){return rect[ant.i][ant.t].x < rect[dps.i][dps.t].x;}
bool comp_y(event ant,event dps){return rect[ant.i][ant.t].y < rect[dps.i][dps.t].y;}
int main(){
int n,d;
cin >> n;d = n*2;
//primeiro ponto = superior esquerdo
//segundo ponto = inferior direito
event linhav[d];
event linhah[d];
for(int i=0;i<n;i++) cin >> rect[i][0].x >> rect[i][0].y >> rect[i][1].x >> rect[i][1].y;
//inicializando
for(int i=0;i<d;i++){linhah[i].i = i<n?i:i-n;linhah[i].t = i<n?0:1;}
for(int i=0;i<d;i++){linhav[i].i = i<n?i:i-n;linhav[i].t = i<n?0:1;}
sort(linhav,linhav+d,comp_x);
sort(linhah,linhah+d,comp_y);
int area = 0;
usado[linhav[0].i] = true;
for(int i=1;i<d;i++){
/*ponto atual*/ /*ponto anterior*/
int delta_x = (rect[linhav[i].i][linhav[i].t].x) - (rect[linhav[i-1].i][linhav[i-1].t].x);
cout << "EVENTO ATUAL.IND = " << linhav[i].i << endl;
cout << "EVENTO ATUAL.TIP = " << linhav[i].t << endl;
cout << endl;
int iniy;
int cont = 0;
for(int j=0;j<d;j++){
int pos = linhah[j].i;
int tip = linhah[j].t;
if(usado[pos]){
if(tip == 0){
cont--;
if(cont==0){
area += (rect[pos][0].y - iniy) * delta_x;
}
}else{
if(cont==0){
iniy = rect[pos][1].y;
}
cont++;
}
}
}
if(linhav[i].t){
usado[linhav[i].i] = false;
}else{
usado[linhav[i].i] = true;
}
}
cout << area << endl;
return 0;
}