QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#467965 | #7846. Glacier Travel | lonelywolf | RE | 0ms | 3948kb | C++20 | 1.8kb | 2024-07-08 18:28:30 | 2024-07-08 18:28:30 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using db = double;
constexpr db eps = 1e-9;
int cmp(db a, db b) {
if (a - b > eps) {
return 1;
}
if (a - b < -eps) {
return -1;
}
return 0;
}
struct Point {
db x, y;
Point operator+(const Point& a) {
return {x + a.x, y + a.y};
}
Point operator-(const Point& a) {
return {x - a.x, y - a.y};
}
Point operator*(const db& a) {
return {x * a, y * a};
}
Point operator/(const db& a) {
return {x / a, y / a};
}
};
db dis(Point a, Point b) {
return hypot(a.x - b.x, a.y - b.y);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(10);
db s;
int n;
cin >> s >> n;
vector<Point> A(n);
for (auto &[x, y] : A) {
cin >> x >> y;
}
vector<db> sum(n);
vector<db> tim;
for (int i = 0; i < n - 1; i++) {
sum[i + 1] = sum[i] + dis(A[i], A[i + 1]);
}
for (int i = 0; i < n; i++) {
if (cmp(sum[i] + s, sum[n - 1]) <= 0) {
tim.push_back(sum[i]);
}
if (cmp(sum[i], s) >= 0) {
tim.push_back(sum[i] - s);
}
}
sort(tim.begin(), tim.end());
int i1 = 0, i2 = 0;
auto calc = [&](db t){
Point p1 = A[i1] + (A[i1 + 1] - A[i1]) / dis(A[i1 + 1], A[i1]) * (t - sum[i1]);
Point p2 = A[i2] + (A[i2 + 1] - A[i2]) / dis(A[i2 + 1], A[i2]) * (t + s - sum[i2]);
return dis(p1, p2);
};
db ans = 1e100;
for (int i = 0; i < tim.size() - 1; i++) {
db t1 = tim[i], t2 = tim[i + 1];
while (cmp(sum[i1], t1) <= 0) {
i1++;
}
while (cmp(sum[i2], t1 + s) <= 0) {
i2++;
}
i1--, i2--;
while (t2 - t1 > eps) {
db lm = (2 * t1 + t2) / 3;
db rm = (t1 + 2 * t2) / 3;
if (calc(lm) > calc(rm)) {
t1 = lm;
} else {
t2 = rm;
}
}
ans = min(ans, calc(t1));
}
cout << ans << "\n";
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3948kb
input:
5 4 20 0 10 0 10 10 0 10
output:
3.5355339059
result:
ok found '3.53553', expected '3.53553', error '0.00000'
Test #2:
score: -100
Runtime Error
input:
3.16227766 9 -2 4 2 4 3 1 4 4 5 1 6 4 10 2 6 1 7 4