QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#323206#8082. Minimum Euclidean DistanceieeTL 0ms3996kbC++231.5kb2024-02-08 20:34:552024-02-08 20:34:55

Judging History

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

  • [2024-02-08 20:34:55]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3996kb
  • [2024-02-08 20:34:55]
  • 提交

answer

#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
using ld = long double;
constexpr ld eps = 1e-8;
using vec = complex<ld>;
using cv = const vec&;
istream& operator >>(istream &in, vec &p) {
	ld x, y;
	in >> x >> y;
	p = {x, y};
	return in;
}
#define x real()
#define y imag()
#define C(a, b) (conj(a) * (b)).y
#define D(a, b) (conj(a) * (b)).x
vec foot(cv o, cv p, cv q) {
	return p + (q - p) * (D(q - p, o - p) / norm(q - p));
}
bool onseg(cv h, cv p, cv q) {
	return h.x > min(p.x, q.x) - eps && h.x < max(p.x, q.x) + eps
	    && h.y > min(p.y, q.y) - eps && h.y < max(p.y, q.y) + eps;
}
ld dist(cv o, cv p, cv q) {
	cv h = foot(o, p, q);
	if (onseg(h, p, q)) return abs(o - h);
	else return min(abs(o - p), abs(o - q));
}
int main() {
	int n, q;
	cin >> n >> q;
	vector<vec> a(n);
	for (vec &p : a) {
		cin >> p;
	}
	ld s0 = 0;
	for (int i = 0; i < n; i++) {
		s0 += C(a[i], a[(i + 1) % n]);
	}
	auto inside = [&](cv p) {
		ld s1 = 0;
		for (int i = 0; i < n; i++) {
			s1 += fabs(C(a[i] - p, a[(i + 1) % n] - p));
		}
		return fabs(s0 - s1) < eps;
	};
	while (q--) {
		vec A, B, O;
		ld r;
		cin >> A >> B, O = (A + B) / ld(2), r = abs(O - A);
		ld d = 1e18;
		if (inside(O)) {
			d = 0;
		} else {
			for (int i = 0; i < n; i++) {
				d = min(d, dist(O, a[i], a[(i + 1) % n]));
			}
		}
		cout << fixed << setprecision(6) << r * r / 2 + d * d << "\n";
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 3
0 0
1 0
1 1
0 1
0 0 1 1
1 1 2 2
1 1 2 3

output:

0.250000
0.750000
1.875000

result:

ok Your answer is acceptable!^ ^

Test #2:

score: 0
Accepted
time: 0ms
memory: 3996kb

input:

48 10
-30 0
-29 -4
-28 -7
-27 -9
-25 -12
-22 -16
-21 -17
-17 -20
-14 -22
-12 -23
-9 -24
-5 -25
-4 -25
0 -24
3 -23
5 -22
8 -20
12 -17
13 -16
16 -12
18 -9
19 -7
20 -4
21 0
21 1
20 5
19 8
18 10
16 13
13 17
12 18
8 21
5 23
3 24
0 25
-4 26
-5 26
-9 25
-12 24
-14 23
-17 21
-21 18
-22 17
-25 13
-27 10
-28 ...

output:

589.500000
51.470588
1051.250000
66.625000
174.125000
562.675000
272.394231
287.385000
689.625000
436.250000

result:

ok Your answer is acceptable!^ ^

Test #3:

score: -100
Time Limit Exceeded

input:

5000 5000
-50000000 0
-49999885 -49450
-49999770 -85675
-49999604 -122394
-49999391 -157604
-49999130 -192731
-49998803 -229143
-49998399 -267196
-49997956 -303872
-49997469 -339362
-49996891 -377221
-49996257 -414903
-49995577 -451819
-49994843 -488600
-49994059 -524941
-49993173 -563137
-49992252 ...

output:

2214785369560632.875000
1632645104370924.374878
3954739966640761.375244
5405105667896787.750000
817274719687553.031372
902260846427661.082458
3194363161448624.125000
1619744446324385.124878
363457485421825.249969
4776425533214308.624023
8267595460255072.723145
2467163193204921.750000
118258028593870...

result: