QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#323210 | #8082. Minimum Euclidean Distance | iee | AC ✓ | 300ms | 4192kb | C++23 | 1.5kb | 2024-02-08 20:47:36 | 2024-02-08 20:47:36 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using db = double;
using ld = long double;
constexpr ld eps = 1e-8;
using vdb = complex<db>;
using vld = complex<ld>;
using cv = const vdb&;
template<class T>
istream& operator >>(istream &in, complex<T> &p) {
T 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
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 = p + (q - p) * (D(q - p, o - p) / norm(q - p));
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<vdb> a(n);
vector<vld> la;
for (vdb &p : a) {
cin >> p;
la.push_back(vld(p.x, p.y));
}
ld s0 = 0;
for (int i = 0; i < n; i++) {
s0 += C(la[i], la[(i + 1) % n]);
}
auto inside = [&](const vld &p) {
ld s1 = 0;
for (int i = 0; i < n; i++) {
s1 += fabs(C(la[i] - p, la[(i + 1) % n] - p));
}
return fabs(s0 - s1) < eps;
};
while (q--) {
vld A, B, O;
ld r;
cin >> A >> B, O = (A + B) / ld(2), r = abs(O - A);
vdb dO(O.x, O.y);
ld d = 1e18;
if (inside(O)) {
d = 0;
} else {
for (int i = 0; i < n; i++) {
d = min(d, dist(dO, 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: 1ms
memory: 3772kb
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: 1ms
memory: 3888kb
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: 0
Accepted
time: 261ms
memory: 3912kb
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:
2214785369560633.223267 1632645104370924.489746 3954739966640761.378418 5405105667896786.913086 817274719687553.013916 902260846427661.104736 3194363161448624.125000 1619744446324385.125000 363457485421825.250000 4776425533214308.832031 8267595460255073.806641 2467163193204921.464844 118258028593870...
result:
ok Your answer is acceptable!^ ^
Test #4:
score: 0
Accepted
time: 146ms
memory: 4012kb
input:
2224 5000 -500000 0 -499999 -30 -499998 -59 -499997 -87 -499996 -114 -499995 -140 -499994 -165 -499993 -189 -499992 -212 -499991 -234 -499990 -255 -499989 -275 -499988 -294 -499987 -312 -499986 -329 -499985 -345 -499984 -360 -499982 -389 -499981 -403 -499979 -430 -499978 -443 -499976 -468 -499975 -4...
output:
931340796015.375037 410570465847.749993 225774975043.749989 686588110927.374931 803635163394.874934 440321806244.749992 781364862674.500003 303496624306.750010 146653887864.749994 1361017661096.749768 409649028457.500003 417747460932.750001 465091810053.374935 1436374892001.875210 500739755666.74999...
result:
ok Your answer is acceptable!^ ^
Test #5:
score: 0
Accepted
time: 145ms
memory: 4020kb
input:
4672 5000 -300 0 -299 -43 -298 -85 -297 -126 -296 -166 -295 -205 -294 -243 -293 -280 -292 -316 -291 -351 -290 -385 -289 -418 -288 -450 -287 -481 -286 -511 -285 -540 -284 -568 -283 -595 -282 -621 -281 -646 -280 -670 -279 -693 -278 -715 -276 -758 -275 -779 -273 -820 -272 -840 -270 -879 -269 -898 -267 ...
output:
356616.500000 121018.500000 0.250000 189.625000 103099.625000 83253.125000 131701.250000 58352.500000 355863.125000 197638.859724 605772.412162 2062.445898 113763.250000 134694.500000 74679.652055 114481.250000 60577.250000 7456.250000 44460.250000 51125.625000 270013.180122 70826.625000 159442.0000...
result:
ok Your answer is acceptable!^ ^
Test #6:
score: 0
Accepted
time: 26ms
memory: 3944kb
input:
576 5000 -300 0 -299 -15 -298 -29 -297 -42 -296 -54 -295 -65 -294 -75 -293 -84 -292 -92 -290 -107 -289 -114 -287 -127 -286 -133 -284 -144 -283 -149 -280 -163 -278 -172 -275 -185 -274 -189 -270 -204 -267 -215 -265 -222 -262 -232 -258 -245 -257 -248 -252 -262 -248 -273 -245 -281 -240 -294 -238 -299 -2...
output:
189295.250000 377943.294416 299473.000000 243821.917197 559270.992228 100367.592340 472743.125000 374450.625000 77260.625000 106891.230769 193578.125000 98895.065415 124020.000000 296138.875000 1209.125000 480040.625000 133543.970690 194311.000000 435910.625000 190937.750000 185722.250000 465855.625...
result:
ok Your answer is acceptable!^ ^
Test #7:
score: 0
Accepted
time: 12ms
memory: 3896kb
input:
336 5000 -300 0 -299 -11 -298 -21 -297 -30 -296 -38 -295 -45 -294 -51 -292 -62 -291 -67 -289 -76 -288 -80 -285 -91 -283 -98 -280 -108 -279 -111 -275 -122 -272 -130 -270 -135 -267 -142 -263 -151 -258 -162 -257 -164 -251 -175 -246 -184 -242 -191 -239 -196 -234 -204 -227 -215 -225 -218 -218 -228 -213 -...
output:
478.125000 408.125000 1341.250000 861.250000 4210.000000 1709.125000 846.250000 1389.125000 722.500000 753.125000 574.250000 1167.125000 439.625000 5650.250000 619.625000 2664.500000 2138.625000 2138.625000 1226.250000 1226.250000 702.125000 2680.625000 199.250000 112.500000 5113.125000 578.250000 1...
result:
ok Your answer is acceptable!^ ^
Test #8:
score: 0
Accepted
time: 15ms
memory: 4020kb
input:
336 5000 -300 0 -299 -11 -298 -21 -297 -30 -296 -38 -295 -45 -294 -51 -292 -62 -291 -67 -289 -76 -288 -80 -285 -91 -283 -98 -280 -108 -279 -111 -275 -122 -272 -130 -270 -135 -267 -142 -263 -151 -258 -162 -257 -164 -251 -175 -246 -184 -242 -191 -239 -196 -234 -204 -227 -215 -225 -218 -218 -228 -213 -...
output:
95.125000 8382.625000 77361.125000 142408.125000 98056.250000 110581.250000 20413.000000 1253.125000 64468.625000 8915.625000 93179.125000 26286.250000 35118.250000 129681.250000 59545.625000 49997.910377 1685.125000 58020.625000 38372.000000 37069.250000 36615.625000 58225.191176 14037.250000 12195...
result:
ok Your answer is acceptable!^ ^
Test #9:
score: 0
Accepted
time: 293ms
memory: 4192kb
input:
5000 5000 -50000000 0 -49999912 -33572 -49999824 -59400 -49999710 -83347 -49999578 -105149 -49999382 -130924 -49999166 -154591 -49998916 -178069 -49998599 -203894 -49998262 -228398 -49997905 -251647 -49997466 -277451 -49997003 -302413 -49996511 -326907 -49995964 -352128 -49995393 -376671 -49994795 -...
output:
481990667522174051.156250 900047257776892010.687500 84250235108292085.906250 357963472278544278.937500 758024710210129325.687500 651805790712522688.437500 422072215223185892.906250 571948904059660576.906250 685946954834849998.062500 781017527404628133.312500 392639124345964350.937500 360254265167699...
result:
ok Your answer is acceptable!^ ^
Test #10:
score: 0
Accepted
time: 300ms
memory: 4188kb
input:
5000 5000 -50000000 0 -49999762 -138397 -49999461 -244153 -49999007 -349713 -49998392 -456086 -49997577 -566637 -49996632 -673023 -49995462 -784273 -49994137 -894156 -49992625 -1005080 -49990945 -1115094 -49989066 -1226720 -49987021 -1337531 -49984788 -1449227 -49982415 -1559155 -49979887 -1668061 -...
output:
259053256470500460.734375 472297859897907085.437500 271976522374482765.765625 930648882061706060.500000 110596174224097031.468750 385963660067947099.937500 441658538323309421.031250 259108189662189412.859375 379723545376251085.312500 43293951022380795.117188 275916442087394777.968750 541970118241836...
result:
ok Your answer is acceptable!^ ^
Extra Test:
score: 0
Extra Test Passed