QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#569516#8082. Minimum Euclidean DistancelongyinTL 1ms3952kbC++202.1kb2024-09-16 23:58:592024-09-16 23:59:00

Judging History

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

  • [2024-09-16 23:59:00]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3952kb
  • [2024-09-16 23:58:59]
  • 提交

answer

#include <bits/stdc++.h>
//#define int long long
#define endl "\n"
using namespace std;

using ll = long long;
const int INF = 1e9;
const int N = 5e3 + 5;
const double eps = 1e-9;

struct Point {
    double x, y;
    using Vec = Point;

    Point operator + (const auto& p) {
        return {x + p.x, y + p.y};
    }

    Point operator - (const auto& p) {
        return {x - p.x, y - p.y};
    }

    Point operator * (const double k) {
        return {x * k, y * k};
    }

    Point operator / (const int k) {
        return {x / k, y / k};
    }

    double cross(const Vec& p) {
        return x * p.y - y * p.x;
    }

    double dis2(const Point& p) {
        return pow(x - p.x, 2) + pow(y - p.y, 2);
    }

    double len2() {
        return pow(x, 2) + pow(y, 2);
    }
} points[N];
using Vec = Point;

double cal(Point& p, Point q) {
    return p.dis2(q);
}

int main() {
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

    int n, q;
    cin >> n >> q;
    for (int i = 1; i <= n; i++) {
        cin >> points[i].x >> points[i].y;
    }
    points[n + 1] = points[1];

    for (int i = 1; i <= q; i++) {
        Point p, q;
        cin >> p.x >> p.y >> q.x >> q.y;
        Point o = (p + q) / 2;
        double r = sqrt(p.dis2(q)) / 2;
        double res = INF;
        bool flag = false;
        for (int j = 1; j <= n; j++) {
            if ((points[j + 1] - points[j]).cross(o - points[j]) <= eps) {
                flag = true;
            }
            double l = 0, r = 1;
            while (r - l > eps) {
                double k = (r - l) / 3;
                double mid1 = l + k, mid2 = r - k;
                if (cal(o, (points[j + 1] - points[j]) * mid1 + points[j]) <= cal(o, (points[j + 1] - points[j]) * mid2 + points[j])) 
                    r = mid2;
                else
                    l = mid1;
            }
            res = min(res, 1.0 * o.dis2((points[j + 1] - points[j]) * l + points[j]));
        }
        if (!flag)
            res = 0;
        res += r * r / 2;
        cout << fixed << setprecision(10) << res << endl;
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3896kb

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: 1ms
memory: 3952kb

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: -100
Time Limit Exceeded

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:

1000001134.6250000000
391704061645588.1250000000
3372744384592591.0000000000
1761094292653339.0000000000
797203335904044.7500000000
407842688547780.0000000000
3194363161448624.0000000000
1619744446324385.0000000000
363457485421825.1875000000
1771731086931932.7500000000
180657347288378.6562500000
767...

result: