QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#356762#6436. Paimon PolygonPorNPtreeWA 1ms6228kbC++144.5kb2024-03-18 10:58:532024-03-18 10:58:54

Judging History

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

  • [2024-03-18 10:58:54]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6228kb
  • [2024-03-18 10:58:53]
  • 提交

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);
}

int operator * (pair<int, int> x, pair<int, int> y)
{
    return x.first * y.second - 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);
    while (T--) {
        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);
            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;
            p2.emplace_back(0, 0);
            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) {
                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));
            }
        }
        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: 6116kb

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: -100
Wrong Answer
time: 1ms
memory: 6228kb

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
28.4408905010
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:

wrong answer 2nd numbers differ - expected: '0.0000000', found: '28.4408905', error = '28.4408905'