QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#577005 | #8082. Minimum Euclidean Distance | xinhuo2005 | WA | 0ms | 3912kb | C++17 | 2.5kb | 2024-09-19 23:55:28 | 2024-09-19 23:55:28 |
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) / (dis(a) * dis(b));
};
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 isInS = [&](pdd a, pdd b, pdd 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 abs(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: 0ms
memory: 3776kb
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: -100
Wrong Answer
time: 0ms
memory: 3912kb
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 553.6250000000 272.3942307692 287.3850000000 689.6250000000 436.2500000000
result:
wrong answer Except 562.675000000000, but found 553.625000000000!QAQ