QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#356791#6436. Paimon PolygonPorNPtreeWA 1ms6304kbC++145.1kb2024-03-18 11:54:592024-03-18 11:55:00

Judging History

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

  • [2024-03-18 11:55:00]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6304kb
  • [2024-03-18 11:54:59]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 5e5 + 5;

pair<int, int> operator - (pair<int, int> x, pair<int, int> y)
{
    return make_pair(x.first - y.first, x.second - y.second);
}

long long operator * (pair<int, int> x, pair<int, int> y)
{
    return 1ll * x.first * y.second - 1ll * x.second * y.first;
}

double atan3(int y, int x)
{
    double f = atan2(y, x);
    return (f > -1e-6 ? f : f + 2 * acos(-1.0));
}

int cmp(pair<int, int> x, pair<int, int> y)
{
    return atan3(x.second, x.first) < atan3(y.second, y.first);
}

pair<int, int> jz;

int cmp2(pair<int, int> x, pair<int, int> y)
{
    return cmp(x - jz, y - jz);
}

int flag, S[N], top, vis[N];

pair< vector< pair<int, int> >, vector< pair<int, int> > > convexHull(vector< pair<int, int> > z)
{
    for (int i = 1; i < (int)z.size(); ++i) {
        if (z[i].second < z[0].second || (z[i].second == z[0].second && z[i].first < z[0].first)) {
            swap(z[0], z[i]);
        }
    }
    jz = z[0];
    sort(z.begin() + 1, z.end(), cmp2);
    S[top = 1] = 0;
    for (int i = 1; i < (int)z.size(); ++i) {
        while (top >= 2 && (z[S[top]] - z[S[top - 1]]) * (z[i] - z[S[top]]) < 0) {
            --top;
        }
        S[++top] = i;
    }
    for (int i = 0; i < (int)z.size(); ++i) {
        vis[i] = 0;
    }
    if (top <= 2) {
        flag = 0;
        return {{}, {}};
    }
    vector< pair<int, int> > S1, S2;
    for (int i = 1; i <= top; ++i) {
        S1.push_back(z[S[i]]);
        vis[S[i]] = 1;
        if ((z[S[i]] - z[S[(i == 1 ? top : i - 1)]]) * (z[S[(i == 1 ? top : i - 1)]] - z[S[(i == 1 ? top - 1 : (i == 2 ? top : i - 2))]]) == 0) {
            flag = 0;
            return {{}, {}};
        }
    }
    for (int i = 0; i < (int)z.size(); ++i) {
        if (!vis[i]) {
            S2.push_back(z[i]);
        }
    }
    return make_pair(S1, S2);
}

double jerry(vector< pair<int, int> > z)
{
    double res = 0;
    for (int i = 0; i < (int)z.size(); ++i) {
        int j = (i + 1 == (int)z.size() ? 0 : i + 1);
        res += hypot(z[i].first - z[j].first, z[i].second - z[j].second);
    }
    return res;
}

signed main()
{
    int T;
    scanf("%d", &T);
    for (int test = 1; test <= T; ++test) {
        int n;
        scanf("%d", &n);
        vector< pair<int, int> > z, tz;
        for (int i = 1, x, y; i <= n; ++i) {
            scanf("%d%d", &x, &y);
            if (test == 17) {
                printf("%d %d\n", x, y);
            }
            z.emplace_back(x, y);
        }
        flag = 1;
        tz = z;
        z.emplace_back(0, 0);
        pair< vector< pair<int, int> >, vector< pair<int, int> > > tmp = convexHull(z);
        double res = 0;
        if (flag) {
            vector< pair<int, int> > p1 = tmp.first, p2 = tmp.second, p3;
            int hv = 0;
            for (int i = 0; i < (int)p1.size(); ++i) {
                hv |= (p1[i] == make_pair(0, 0));
            }
            if (hv) {
                p2.emplace_back(0, 0);
                if ((int)p2.size() >= 3) {
                    tmp = convexHull(p2);
                    p2 = tmp.first, p3 = tmp.second;
                    if (flag && p3.empty()) {
                        res = max(res, jerry(p1) + jerry(p2));
                    }
                }
            }
        }
        z.pop_back();
        sort(z.begin(), z.end(), cmp);
        vector<int> hv;
        for (int i = 0; i < (int)z.size(); ++i) {
            if ((z[i] - z[(i + n - 1) % n]) * (z[(i + 1) % n] - z[i]) <= 0) {
                hv.push_back(i);
            }
        }
        if ((int)hv.size() > 4) {
            printf("%.10lf\n", res);
            continue;
        }
        double ts = jerry(z);
        for (int i = 0, j = 1; i < (int)z.size(); ++i) {
            while ((j + 1) % n != i && (make_pair(0, 0) - z[i]) * z[(j + 1) % n] <= 0) {
                j = (j + 1) % n;
            }
            if ((make_pair(0, 0) - z[i]) * z[(j + 1) % n] <= 0 || (make_pair(0, 0) - z[j]) * z[(i + 1) % n] <= 0 ||
                (make_pair(0, 0) - z[i]) * z[(i + 1) % n] == 0 || (make_pair(0, 0) - z[j]) * z[(j + 1) % n] == 0) {
                continue;
            }
            int ok = 1;
            for (auto x : hv) {
                if (x != i && x != j && x != (i + 1) % n && x != (j + 1) % n) {
                    ok = 0;
                    break;
                }
            }
            if (ok) {
                res = max(res, ts + hypot(z[i].first, z[i].second)
                                  + hypot(z[(i + 1) % n].first, z[(i + 1) % n].second)
                                  + hypot(z[j].first, z[j].second)
                                  + hypot(z[(j + 1) % n].first, z[(j + 1) % n].second)
                                  - hypot(z[i].first - z[(i + 1) % n].first, z[i].second - z[(i + 1) % n].second)
                                  - hypot(z[j].first - z[(j + 1) % n].first, z[j].second - z[(j + 1) % n].second));
            }
        }
        if (T < 50) printf("%.10lf\n", res);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
4
0 3
3 0
2 3
3 2
5
4 0
5 -5
-4 -2
1 -2
-5 -2
4
0 1
1 0
0 2
1 1

output:

17.2111025509
36.6326947621
0.0000000000

result:

ok 3 numbers

Test #2:

score: 0
Accepted
time: 1ms
memory: 6304kb

input:

14
4
0 3
1 3
3 1
3 0
4
-4 0
5 3
0 -4
-1 0
5
4 4
5 0
3 3
3 2
-4 2
5
1 1
2 4
1 4
0 4
-1 1
4
4 5
-2 4
1 4
-5 -2
5
3 5
3 -1
4 -5
4 1
2 4
5
4 0
5 -5
-4 -2
1 -2
-5 -2
5
3 4
3 5
-5 -1
1 2
4 1
5
-5 -3
3 -3
-3 -3
2 -3
-4 5
5
0 1
-3 -1
-3 -3
-4 -4
-3 0
6
1 -3
-3 -3
2 -2
-3 1
-4 -5
3 -3
6
-1 -4
-3 0
0 4
-4 -3
...

output:

14.3245553203
0.0000000000
30.6896447944
18.7482240257
30.2540122179
27.8210682918
36.6326947621
33.4097258671
29.5562146354
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000

result:

ok 14 numbers

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 6284kb

input:

100
6
-4 1
-1 4
1 4
-4 -1
-2 3
3 2
7
-5641417 962017
-5641417 -962017
-5719589 193284
-5693492 -578972
-5693492 578972
-5563601 1340673
-5719589 -193284
9
-25 55
58 15
-13 14
-1 19
-60 6
-17 8
11 15
16 58
16 11
10
398546 -221163
-87181 -447383
-221163 -398546
-467649 -57196
55334 -452427
-427086 -19...

output:

359.1097585858
-47 82
-16 94
-95 0
-89 -32
-92 1
-48 -82
-16 -94
-73 61
16 94
-73 -61
0.0000000000

result:

wrong answer 1st numbers differ - expected: '25.1141681', found: '359.1097586', error = '13.2990904'