QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#577173 | #8082. Minimum Euclidean Distance | xinhuo2005 | WA | 243ms | 4020kb | C++17 | 2.5kb | 2024-09-20 08:45:57 | 2024-09-20 08:45:59 |
Judging History
answer
#include<bits/stdc++.h>
using ll = long long;
const int mod = 998244353;
#define pdd std::pair<double, double>
#define x first
#define y second
const double PI = acos(-1);
std::pair<double, double> operator- (const std::pair<double, double> a, const std::pair<double, double> b) {
return {a.first - b.first, a.second - b.second};
}
void solve() {
int n, q;
std::cin >> n >> q;
std::vector<std::pair<double, double>> A(n);
for (int i = 0; i < n; i++) {
std::cin >> A[i].first >> A[i].second;
}
auto dis = [&](pdd a) {
return sqrt(a.x * a.x + a.y * a.y);
};
auto Dot = [&](pdd a, pdd b) {
return (a.x * b.x + a.y * b.y);
};
auto Cro = [&](pdd a, pdd b) {
return a.x * b.y - a.y * b.x;
};
auto cmp = [&](double x) {
if (fabs(x - 1e-8) <= 0.0) return 0.0;
return x;
};
auto isCon = [&](double xl, double yl, double xr, double yr) {
double x = (xl + xr) / 2, y = (yl + yr) / 2;
pdd o = {x, y};
std::vector<int> ok(n);
for (int i = 0; i < n; i++) {
double x = Cro(A[i] - A[(i + 1) % n], o - A[(i + 1) % n]);
if (cmp(x) == 0.0) return true;
if (cmp(x) < 0) ok[i] = -1;
else ok[i] = 1;
}
if (*std::max_element(ok.begin(), ok.end()) == *std::min_element(ok.begin(), ok.end())) return true;
return false;
};
auto dis_ps = [&](pdd a, pdd b, pdd p) {
if ((cmp(Dot(p - a, a - b)) >= 0) ^ (cmp(Dot(p - b, a - b)) >= 0)) {
return fabs(Cro(a - p, b - p)) / dis(a - b);
}
else {
return std::min(dis(p - a), dis(p - b));
}
};
while (q--) {
double xl, yl, xr, yr;
std::cin >> xl >> yl >> xr >> yr;
double ans = dis({xl - xr, yl - yr}) / 2;
ans = ans * ans / 2.0;
pdd o = {(xl + xr) / 2, (yl + yr) / 2};
if (!isCon(xl, yl, xr, yr)) {
double mn = 1e9;
for (int i = 0; i < n; i++) {
mn = std::min(mn, dis_ps(A[i], A[(i + 1) % n], o));
}
ans += mn * mn;
}
std::cout << std::fixed << std::setprecision(10);
std::cout << ans << "\n";
}
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t = 1;
// std::cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3936kb
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.2500000000 0.7500000000 1.8750000000
result:
ok Your answer is acceptable!^ ^
Test #2:
score: 0
Accepted
time: 0ms
memory: 3892kb
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.5000000000 51.4705882353 1051.2500000000 66.6250000000 174.1250000000 562.6750000000 272.3942307692 287.3850000000 689.6250000000 436.2500000000
result:
ok Your answer is acceptable!^ ^
Test #3:
score: 0
Accepted
time: 243ms
memory: 3888kb
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.0000000000 1632645104370924.5000000000 3954739966640761.0000000000 5405105667896786.0000000000 817274719687553.1250000000 902260846427661.1250000000 3194363161448624.0000000000 1619744446324385.0000000000 363457485421825.1875000000 4776425533214309.0000000000 8267595460255074.000000...
result:
ok Your answer is acceptable!^ ^
Test #4:
score: 0
Accepted
time: 128ms
memory: 4020kb
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.3750000000 410570465847.7500000000 225774975043.7500000000 686588110927.3748779297 803635163394.8750000000 440321806244.7500000000 781364862674.5000000000 303496624306.7500000000 146653887864.7500000000 1361017661096.7497558594 409649028457.5000000000 417747460932.7500000000 46509181005...
result:
ok Your answer is acceptable!^ ^
Test #5:
score: -100
Wrong Answer
time: 157ms
memory: 3948kb
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.5000000000 121018.5000000000 0.2500000000 189.6250000000 103099.6250000000 83253.1250000000 131701.2500000000 58352.5000000000 355863.1250000000 197638.8597240473 605772.4121621621 2062.4458977408 113763.2500000000 134694.5000000000 74679.6520547945 114481.2500000000 60577.2500000000 7456.250...
result:
wrong answer Except 57754.614864864903, but found 7183.125000000000!QAQ