QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#468033#7846. Glacier TravellonelywolfWA 0ms4036kbC++202.0kb2024-07-08 18:48:262024-07-08 18:48:27

Judging History

你现在查看的是最新测评结果

  • [2024-07-08 18:48:27]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4036kb
  • [2024-07-08 18:48:26]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using db = double;

constexpr db eps = 1e-6;

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;
	Point dir1, dir2;
	auto calc = [&](db t) {
		Point a = A[i1] + dir1 * (t - sum[i1]); 
		Point b = A[i2] + dir2 * (t + s - sum[i2]);
		return dis(a, b);
	};
	db ans = 1e18;
	for (int i = 0; i < tim.size() - 1; i++) {
		db t1 = tim[i], t2 = tim[i + 1];
		if (cmp(t1, t2) == 0 || cmp(t1, sum[n - 1]) == 1 || cmp(t2, sum[n - 1]) == 1 || cmp(t1, s) == -1 || cmp(t2, s) == -1) {
            continue;
        }
		while (cmp(sum[i1], t1) <= 0) {
			i1++;
		}
		while (cmp(sum[i2], t1 + s) <= 0) {
			i2++;
		}
		i1--, i2--;

		dir1 = (A[i1 + 1] - A[i1]) / dis(A[i1 + 1], A[i1]);
	 	dir2 = (A[i2 + 1] - A[i2]) / dis(A[i2 + 1], A[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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3904kb

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: 0
Accepted
time: 0ms
memory: 3940kb

input:

3.16227766
9
-2 4
2 4
3 1
4 4
5 1
6 4
10 2
6 1
7 4

output:

0.9999999999

result:

ok found '1.00000', expected '1.00000', error '0.00000'

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 4036kb

input:

20
5
9 38
36 16
-5 36
-24 15
30 37

output:

4.4473172882

result:

wrong answer 1st numbers differ - expected: '2.29360', found: '4.44732', error = '0.93902'