forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB.cpp
More file actions
113 lines (91 loc) · 2.54 KB
/
B.cpp
File metadata and controls
113 lines (91 loc) · 2.54 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
#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
#define SZ(X) ((int) ((X).size()))
using namespace std;
struct Point {
double x, y;
Point() {}
Point(double x, double y) : x(x), y(y) {}
Point operator - (const Point& a) const {
return Point(x-a.x, y-a.y);
}
Point operator + (const Point& a) const {
return Point(x+a.x, y+a.y);
}
Point operator * (double k) const {
return Point(x*k, y*k);
}
double len() {
return sqrt(x*x + y*y);
}
bool read() {
if (!(cin >> x >> y)) return false;
return true;
}
} start, target, wind1, wind2;
double vmax, t;
bool check1(double k) {
Point dist = target - start;
dist = dist - wind1 * k;
double vneed = dist.len() / k;
return vneed <= vmax;
}
double solve1() {
double l = 1e-9, r = t;
double res = t * 10;
REP(turn,10000) {
double mid = (l + r) / 2.0;
if (check1(mid)) {
res = mid;
r = mid;
}
else l = mid;
}
return res;
}
bool check2(double k) {
Point dist = target - start;
dist = dist - wind1 * t;
dist = dist - wind2 * (k - t);
double vneed = dist.len() / k;
return vneed <= vmax;
}
double solve2() {
double l = t, r = 1e50;
double res = r;
REP(turn,10000) {
double mid = (l + r) / 2.0;
if (check2(mid)) {
res = mid;
r = mid;
}
else l = mid;
}
return res;
}
int main() {
ios :: sync_with_stdio(false);
int x1, y1, x2, y2;
while (cin >> x1 >> y1 >> x2 >> y2) {
start = Point(x1, y1);
target = Point(x2, y2);
cin >> vmax >> t;
wind1.read();
wind2.read();
if (x1 == x2 && y1 == y2) {
cout << 0 << endl;
continue;
}
double res = solve1();
if (res > t) res = solve2();
cout << (fixed) << setprecision(12) << res << endl;
}
}