#include <bits/stdc++.h>
#define pow(x, y) (long double)(pow(x, y))
using namespace std;
struct coord{
int x, y;
};
vector <coord> a;
int N, L;
/*long double dis(int ax, ay, long double ans) {
return (long double)(sqrt(pow(ay, 2) + pow(ax - ans, 2)));
}
long double distance(int i, int j) {
long long num = pow(a[i].y, 2) - pow(a[j].y, 2) - pow(a[j].x, 2) + pow(a[i].x, 2);
long long den = 2 * (-a[j].x + a[i].x);
if (den == 0) return sqrt(num);
long double frac = (long double)(num) / (long double)(den);
return frac;
}*/
bool solve(long double mid) {
long double right(0);
for (int i(0); i < a.size(); i++) {
if (abs(a[i].y) > mid) continue;
long double iLeft = (long double)(a[i].x) - (long double)(sqrt(pow(mid, 2) - pow(a[i].y, 2)));
long double iRight = (long double)(a[i].x) + (long double)(sqrt(pow(mid, 2) - pow(a[i].y, 2)));
if (iLeft <= right) right = max(right,iRight);
}
return (right >= L);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N >> L;
a.clear();
int x, y; cin >> x >> y;
a.push_back({x, y});
for (int i(0); i < N - 1; i++) {
int ax, ay;
cin >> ax >> ay;
a.push_back({ax, ay});
}
long double l(0), r(1e9);
long double ans(0);
while (r - l > 0.00001) {
long double mid = l + (r - l) / 2;
if (solve(mid)){
r = mid;
ans = r;
}
else l = mid;
}
cout << l << '\n';
return 0;
}
Compilation message
mobile.cpp: In function 'bool solve(long double)':
mobile.cpp:25:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<coord>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for (int i(0); i < a.size(); i++) {
| ~~^~~~~~~~~~
mobile.cpp: In function 'int main()':
mobile.cpp:47:14: warning: variable 'ans' set but not used [-Wunused-but-set-variable]
47 | long double ans(0);
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Incorrect |
3 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Incorrect |
4 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
1604 KB |
Output is correct |
2 |
Incorrect |
34 ms |
1592 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
1500 KB |
Output is correct |
2 |
Correct |
22 ms |
1500 KB |
Output is correct |
3 |
Incorrect |
24 ms |
1500 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
1656 KB |
Output is correct |
2 |
Incorrect |
35 ms |
1496 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
43 ms |
1420 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
44 ms |
1500 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
210 ms |
6260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
214 ms |
5832 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
262 ms |
10176 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
221 ms |
9132 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
289 ms |
8920 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
261 ms |
8688 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
329 ms |
10184 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
301 ms |
10464 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
420 ms |
10692 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
366 ms |
10524 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |