forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC.cpp
More file actions
104 lines (81 loc) · 2.4 KB
/
C.cpp
File metadata and controls
104 lines (81 loc) · 2.4 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
#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 DEBUG(X) { cout << #X << " = " << 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
#define SZ(x) ((int) (x).size())
using namespace std;
#define double long double
const double EPS = 1e-9;
struct Point {
double x, y;
Point() {}
Point(double x, double y) : x(x), y(y) {}
friend istream& operator >> (istream& cin, Point& p) {
cin >> p.x >> p.y;
return cin;
}
friend ostream& operator << (ostream& cout, Point& p) {
cout << p.x << ' ' << p.y;
return cout;
}
};
struct Line {
double a, b, c;
Line(Point A, Point B) {
a = B.y - A.y;
b = A.x - B.x;
c = - (a * A.x + b * A.y);
}
friend ostream& operator << (ostream& cout, Line& l) {
cout << l.a << ' ' << l.b << ' ' << l.c << endl;
return cout;
}
double dist(Point p) {
return fabs(a*p.x + b*p.y + c) / sqrt(a*a + b*b);
}
};
#define y1 y1_____
double y1, y2, yw, R;
Point ball;
double f(double x) {
Point wall(x, yw);
Point ref(2 * x - ball.x, ball.y); // reflection of the ball
Line l(wall, ref);
return - l.c / l.b;
}
bool check(double x) {
Point wall(x, yw);
Point ref(2 * x - ball.x, ball.y); // reflection of the ball
Line l(wall, ref);
if (l.dist(Point(0, y2)) < R) {
return false;
}
return true;
}
int main() {
ios :: sync_with_stdio(0); cin.tie(0);
cout << (fixed) << setprecision(12);
while (cin >> y1 >> y2 >> yw >> ball >> R) {
double l = EPS, r = ball.x - EPS, res = -1.0;
if (l > r) {
cout << -1.0 << endl;
continue;
}
yw -= R; // now we can consider ball as 1 point
REP(turn,1000) {
double mid = (l + r) / 2.0;
if (f(mid) > y1 + R) {
res = mid;
l = mid;
}
else r = mid;
}
if (!check(res)) res = -1.0;
cout << res << endl;
}
}