Skip to content

Commit 3635cbd

Browse files
Add files via upload
1 parent 48907cd commit 3635cbd

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#pragma GCC optimize("Ofast")
2+
#pragma GCC optimize("unroll-loops")
3+
#include <bits/stdc++.h>
4+
using namespace std;
5+
6+
typedef long long ll;
7+
typedef vector<int> vi;
8+
#define fast_cin() \
9+
ios_base::sync_with_stdio(false); \
10+
cin.tie(NULL); \
11+
cout.tie(NULL);
12+
13+
double X, Y;
14+
int n;
15+
vector<tuple<int, int, double>> shields; // bottom, top, factor
16+
17+
double f(double horizontalSpeed) {
18+
// returns the x coordinate of the point when the y coordinate is Y
19+
double x = 0;
20+
double y = 0;
21+
22+
for (auto [shield_bottom, shield_top, factor] : shields) {
23+
// go to the shield
24+
double dist_to_shield = shield_bottom - y;
25+
double time_to_shield = dist_to_shield;
26+
x += time_to_shield * horizontalSpeed;
27+
28+
// go through the shield
29+
double dist_through_shield = shield_top - shield_bottom;
30+
double time_through_shield = dist_through_shield;
31+
x += time_through_shield * factor * horizontalSpeed;
32+
33+
y = shield_top;
34+
}
35+
36+
// go to the end
37+
double dist_to_end = Y - y;
38+
double time_to_end = dist_to_end;
39+
x += time_to_end * horizontalSpeed;
40+
41+
return x;
42+
}
43+
44+
int main() {
45+
fast_cin();
46+
bool negate = false;
47+
cin >> X >> Y;
48+
if (X < 0) {
49+
negate = true;
50+
X = -X;
51+
}
52+
cin >> n;
53+
shields.resize(n);
54+
for (int i = 0; i < n; i++) {
55+
int x, y;
56+
double f;
57+
cin >> x >> y >> f;
58+
shields[i] = make_tuple(x, y, f);
59+
}
60+
61+
double l = 0;
62+
double r = 1e9;
63+
for (int i = 0; i < 500; i++) {
64+
double m = (l + r) / 2;
65+
if (f(m) < X) { // too slow
66+
l = m;
67+
} else {
68+
r = m;
69+
}
70+
}
71+
72+
cout << setprecision(10);
73+
if (negate) {
74+
cout << -l << endl;
75+
} else {
76+
cout << l << endl;
77+
}
78+
79+
return 0;
80+
}

0 commit comments

Comments
 (0)