QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#577003#8082. Minimum Euclidean Distancexinhuo2005WA 0ms4000kbC++172.5kb2024-09-19 23:53:342024-09-19 23:53:34

Judging History

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

  • [2024-09-19 23:53:34]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4000kb
  • [2024-09-19 23:53:34]
  • 提交

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 (abs(x - 1e-8) <= 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: 0
Wrong Answer
time: 0ms
memory: 4000kb

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.2500000000
0.6250000000

result:

wrong answer Except 0.750000000000, but found 0.250000000000!QAQ