Skip to content

Commit 5ab3634

Browse files
committed
Solved problem 65C from codeforces
1 parent ede7763 commit 5ab3634

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int const N = 1e4 + 10;
6+
7+
struct point {
8+
double x, y, z;
9+
10+
point() {}
11+
12+
point(double x, double y, double z) : x(x), y(y), z(z) {}
13+
14+
bool operator==(const point &p) const {
15+
return x == p.x && y == p.y && z == p.z;
16+
}
17+
18+
point operator-(const point &p) const {
19+
return point(x - p.x, y - p.y, z - p.z);
20+
}
21+
22+
point operator+(const point &p) const {
23+
return point(x + p.x, y + p.y, z + p.z);
24+
}
25+
26+
point operator*(const double &o) const {
27+
return point(x * o, y * o, z * o);
28+
}
29+
30+
double dist(const point &p) const {
31+
return sqrt(pow(x - p.x, 2) + pow(y - p.y, 2) + pow(z - p.z, 2));
32+
}
33+
} points[N];
34+
point p;
35+
36+
int n;
37+
double vp, vs, t[N];
38+
39+
int main() {
40+
scanf("%d", &n);
41+
for(int i = 0; i <= n; ++i)
42+
scanf("%lf %lf %lf", &points[i].x, &points[i].y, &points[i].z);
43+
scanf("%lf %lf", &vp, &vs);
44+
scanf("%lf %lf %lf", &p.x, &p.y, &p.z);
45+
46+
if(p == points[0]) {
47+
puts("YES");
48+
puts("0.0000000000");
49+
printf("%0.10lf %0.10lf %0.10lf\n", p.x, p.y, p.z);
50+
return 0;
51+
}
52+
53+
for(int i = 1; i <= n; ++i)
54+
t[i] = points[i].dist(points[i - 1]) / vs + t[i - 1];
55+
56+
for(int i = 1; i <= n; ++i) {
57+
if(p.dist(points[i]) / vp - 1e-9 < t[i]) {
58+
double l = 0, r = 1, mid;
59+
point res;
60+
for(int j = 0; j < 100; ++j) {
61+
mid = (l + r) / 2;
62+
point cur = points[i - 1] + (points[i] - points[i - 1]) * mid;
63+
64+
if(p.dist(cur) / vp - 1e-15 < points[i - 1].dist(cur) / vs + t[i - 1])
65+
res = cur, r = mid;
66+
else
67+
l = mid;
68+
}
69+
70+
puts("YES");
71+
printf("%0.10lf\n", p.dist(res) / vp);
72+
printf("%0.10lf %0.10lf %0.10lf\n", res.x, res.y, res.z);
73+
74+
return 0;
75+
}
76+
}
77+
78+
puts("NO");
79+
80+
return 0;
81+
}

CodeForces/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
- [59A. Word](http://codeforces.com/problemset/problem/59/A)
3434
- [61A. Ultra-Fast Mathematician](http://codeforces.com/contest/61/problem/A)
3535
- [61E. Enemy is weak](http://codeforces.com/contest/61/problem/E)
36+
- [65C. Harry Potter and the Golden Snitch](http://codeforces.com/contest/65/problem/C)
3637
- [68A. Irrational problem](http://codeforces.com/problemset/problem/68/A)
3738
- [69A. Young Physicist](http://codeforces.com/problemset/problem/69/A)
3839
- [69C. Game](http://codeforces.com/contest/69/problem/C)

0 commit comments

Comments
 (0)