forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathE.cpp
More file actions
198 lines (159 loc) · 5.83 KB
/
E.cpp
File metadata and controls
198 lines (159 loc) · 5.83 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)
#define REP(i,a) for(int i=0,_a=(a); i<_a; i++)
#define EACH(it,a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define DEBUG(x) { cout << #x << " = "; cout << (x) << endl; }
#define PR(a,n) { cout << #a << " = "; FOR(_,1,n) cout << a[_] << ' '; cout << endl; }
#define PR0(a,n) { cout << #a << " = "; REP(_,n) cout << a[_] << ' '; cout << endl; }
#define sqr(x) ((x) * (x))
#define ll long long
using namespace std;
#undef M_PI
const double M_PI = acos(-1.0);
#define EPS 1e-6
double DEG_to_RAD(double d) { return d * M_PI / 180.0; }
double RAD_to_DEG(double r) { return r * 180.0 / M_PI; }
inline int cmp(double a, double b) {
return (a < b - EPS) ? -1 : ((a > b + EPS) ? 1 : 0);
}
struct Point {
double x, y;
Point(double x = 0.0, double y = 0.0) : x(x), y(y) {}
Point operator + (Point a) { return Point(x+a.x, y+a.y); }
Point operator - (Point a) { return Point(x-a.x, y-a.y); }
Point operator * (double k) { return Point(x*k, y*k); }
Point operator / (double k) { return Point(x/k, y/k); }
double operator * (Point a) { return x*a.x + y*a.y; } // dot product
double operator % (Point a) { return x*a.y - y*a.x; } // cross product
int cmp(Point q) const { if (int t = ::cmp(x,q.x)) return t; return ::cmp(y,q.y); }
#define Comp(x) bool operator x (Point q) const { return cmp(q) x 0; }
Comp(>) Comp(<) Comp(==) Comp(>=) Comp(<=) Comp(!=)
#undef Comp
Point conj() { return Point(x, -y); }
double norm() { return x*x + y*y; }
// Note: There are 2 ways for implementing len():
// 1. sqrt(norm()) --> fast, but inaccurate (produce some values that are of order X^2)
// 2. hypot(x, y) --> slow, but much more accurate
double len() { return sqrt(norm()); }
Point rotate(double alpha) {
double cosa = cos(alpha), sina = sin(alpha);
return Point(x * cosa - y * sina, x * sina + y * cosa);
}
void read() {
cin >> x >> y;
}
};
int ccw(Point a, Point b, Point c) {
return cmp((b-a)%(c-a),0);
}
double angle(Point a, Point o, Point b) { // angle AOB
a = a - o; b = b - o;
return acos((a * b) / sqrt(a.norm() * b.norm()));
}
// Distance from p to Line ab (closest Point --> c)
double distToLine(Point p, Point a, Point b, Point &c) {
Point ap = p - a, ab = b - a;
double u = (ap * ab) / ab.norm();
c = a + (ab * u);
return (p-c).len();
}
// Distance from p to segment ab (closest Point --> c)
double distToLineSegment(Point p, Point a, Point b, Point &c) {
Point ap = p - a, ab = b - a;
double u = (ap * ab) / ab.norm();
if (u < 0.0) {
c = Point(a.x, a.y);
return (p - a).len();
}
if (u > 1.0) {
c = Point(b.x, b.y);
return (p - b).len();
}
return distToLine(p, a, b, c);
}
// NOTE: WILL NOT WORK WHEN a = b = 0.
struct Line {
double a, b, c;
Point A, B; // Added for polygon intersect line. Do not rely on assumption that these are valid
Line(double a, double b, double c) : a(a), b(b), c(c) {}
Line(Point A, Point B) : A(A), B(B) {
a = B.y - A.y;
b = A.x - B.x;
c = - (a * A.x + b * A.y);
}
Line(Point P, double m) {
a = -m; b = 1;
c = -((a * P.x) + (b * P.y));
}
double f(Point A) {
return a*A.x + b*A.y + c;
}
};
bool areParallel(Line l1, Line l2) {
return cmp(l1.a*l2.b, l1.b*l2.a) == 0;
}
bool areSame(Line l1, Line l2) {
return areParallel(l1 ,l2) && cmp(l1.c*l2.a, l2.c*l1.a) == 0
&& cmp(l1.c*l2.b, l1.b*l2.c) == 0;
}
bool areIntersect(Line l1, Line l2, Point &p) {
if (areParallel(l1, l2)) return false;
double dx = l1.b*l2.c - l2.b*l1.c;
double dy = l1.c*l2.a - l2.c*l1.a;
double d = l1.a*l2.b - l2.a*l1.b;
p = Point(dx/d, dy/d);
return true;
}
void closestPoint(Line l, Point p, Point &ans) {
if (fabs(l.b) < EPS) {
ans.x = -(l.c) / l.a; ans.y = p.y;
return;
}
if (fabs(l.a) < EPS) {
ans.x = p.x; ans.y = -(l.c) / l.b;
return;
}
Line perp(l.b, -l.a, - (l.b*p.x - l.a*p.y));
areIntersect(l, perp, ans);
}
void reflectionPoint(Line l, Point p, Point &ans) {
Point b;
closestPoint(l, p, b);
ans = p + (b - p) * 2;
}
bool order(Point A, Point B, Point C) {
return min(A.x, C.x) <= B.x && B.x <= max(A.x, C.x)
&& min(A.y, C.y) <= B.y && B.y <= max(A.y, C.y);
}
bool intersect(Point A, Point B, Point X, Point Y) {
if (ccw(A, B, X) == 0 && order(A, X, B)) return true;
if (ccw(A, B, Y) == 0 && order(A, Y, B)) return true;
if (ccw(X, Y, A) == 0 && order(X, A, Y)) return true;
if (ccw(X, Y, B) == 0 && order(X, B, Y)) return true;
if (ccw(A, B, X) * ccw(A, B, Y) < 0
&& ccw(X, Y, A) * ccw(X, Y, B) < 0)
return true;
return false;
}
int main() {
Point A, B, M1, M2, W1, W2;
while (cin >> A.x >> A.y) {
B.read();
W1.read(); W2.read();
M1.read(); M2.read();
Line W(W1, W2);
Line M(M1, M2);
Point A2, B2, AO, BO;
reflectionPoint(M, A, A2);
reflectionPoint(M, B, B2);
areIntersect(Line(M1, M2), Line(A2, B), AO);
areIntersect(Line(M1, M2), Line(B2, A), BO);
if (!intersect(A, B, W1, W2) && !intersect(A, B, M1, M2)) cout << "YES";
else if (!intersect(A, AO, W1, W2) && !intersect(AO, B, W1, W2) && intersect(A2, B, M1, M2)) cout << "YES";
else if (!intersect(B, BO, W1, W2) && !intersect(BO, A, W1, W2) && intersect(B2, A, M1, M2)) cout << "YES";
else cout << "NO";
cout << endl;
}
return 0;
}