forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurbandesign.cpp
107 lines (91 loc) · 2.25 KB
/
urbandesign.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
105
106
#include <iostream>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
typedef long double ld;
struct point {
ld x, y;
point(ld xloc, ld yloc) : x(xloc), y(yloc){}
point(){}
point& operator= (const point& other) {
x = other.x, y = other.y;
return *this;
}
int operator == (const point& other) const {
return (other.x == x && other.y == y);
}
int operator != (const point& other) const {
return !(other.x == x && other.y == y);
}
bool operator< (const point& other) const {
return (x < other.x ? true : (x == other.x && y < other.y));
}
};
struct vect {ld i, j;};
struct segment {
point p1, p2;
segment(point a, point b) : p1(a), p2(b){}
segment(){}
};
#define COLINEAR 0
#define CW 1
#define CCW 2
ld crossProduct(point A, point B, point C) {
vect AB, AC;
AB.i = B.x - A.x;
AB.j = B.y - A.y;
AC.i = C.x - A.x;
AC.j = C.y - A.y;
return (AB.i * AC.j - AB.j * AC.i);
}
int orientation(point p, point q, point r) {
int val = (int)crossProduct(p, q, r);
if(val == 0) {
return COLINEAR;
}
return (val > 0) ? CW : CCW;
}
bool straddle(segment s1, segment s2) {
ld cross1 = crossProduct(s1.p1, s1.p2, s2.p1);
ld cross2 = crossProduct(s1.p1, s1.p2, s2.p2);
if((cross1 > 0 && cross2 > 0) || (cross1 < 0 && cross2 < 0)) {
return false;
}
if(cross1 == 0 && cross2 == 0 && orientation(s1.p2, s2.p1, s2.p2) != COLINEAR) {
return false;
}
return true;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
vector<segment> lines;
int n;
cin >> n;
for(int i = 0; i < n; i++) {
point p1, p2;
cin >> p1.x >> p1.y >> p2.x >> p2.y;
segment s(p1, p2);
lines.push_back(s);
}
int m;
cin >> m;
for(int i = 0; i < m; i++) {
point p1, p2;
cin >> p1.x >> p1.y >> p2.x >> p2.y;
segment s(p1, p2);
int total = 0;
for(int i = 0; i < n; i++) {
if(straddle(lines[i], s)) {
total++;
}
}
if(total % 2 == 0) {
cout << "same" << endl;
}
else {
cout << "different" << endl;
}
}
}