QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#378983 | #8022. Walker | comeintocalm# | TL | 0ms | 0kb | C++17 | 973b | 2024-04-06 15:37:16 | 2024-04-06 15:37:17 |
answer
#include <bits/stdc++.h>
#define LL long long
#define db double
using namespace std;
const db eps = 1e-15;
int T;
db n, p[2], v[2];
db calc (int x, db l, db r) {
return (r - l + min (p[x] - l, r - p[x])) / v[x];
}
int main() {
int i,j,k;
scanf ("%d", &T);
while (T--) {
scanf ("%lf%lf%lf%lf%lf", &n, &p[0], &v[0], &p[1], &v[1]);
if (p[0] > p[1]) swap (p[0], p[1]), swap (v[0], v[1]);
db ans = min (calc (0, 0, n), calc (1, 0, n));
//ans = min (ans, max (0, 0, p[1]))
//cout << n << endl;
//cout << calc (0, 0, n) << endl;
db L = p[0], R = p[1];
while (L + eps < R) {
db fm = (R - L) / 3.0, m1 = L + fm, m2 = R - fm;
db a1 = max (calc (0, 0, m1), calc (1, m1, n));
db a2 = max (calc (0, 0, m2), calc (1, m2, n));
ans = min (ans, a1);
ans = min (ans, a2);
if (a1 < a2) R = m2;
else L = m1;
}
ans = min (ans, max (calc (0, 0, L), calc (1, L, n)));
printf ("%.13lf\n", ans);
}
return 0;
}
详细
Test #1:
score: 0
Time Limit Exceeded
input:
2 10000.0 1.0 0.001 9999.0 0.001 4306.063 4079.874 0.607 1033.423 0.847