QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#576961#8082. Minimum Euclidean Distancexinhuo2005WA 1ms4220kbC++202.4kb2024-09-19 23:35:252024-09-19 23:35:26

Judging History

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

  • [2024-09-19 23:35:26]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4220kb
  • [2024-09-19 23:35:25]
  • 提交

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 isCon = [&](double xl, double yl, double xr, double yr) {
        double x = (xl + xr) / 2, y = (yl + yr) / 2;
        pdd o = {x, y};
        std::vector<pdd> v(n);
        for (int i = 0; i < n; i++) {
            v[i] = a[i] - o; 
        }
        double sum = 0;
        for (int i = 0; i < n; i++) {
            sum += acos(Dot(v[i], v[(i + 1) % n]));
        }
        if (cmp(sum - 2 * PI) == 0.0) {
            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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 4172kb

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: 4220kb

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
52.0000000000
1051.2500000000
66.6250000000
174.3750000000
562.8750000000
272.8750000000
287.8750000000
689.6250000000
436.2500000000

result:

wrong answer Except 51.470588235300, but found 52.000000000000!QAQ