QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#356790#6436. Paimon PolygonPorNPtreeWA 1ms6056kbC++145.1kb2024-03-18 11:54:442024-03-18 11:54:44

Judging History

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

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

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

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 6056kb

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:


result:

wrong output format Unexpected end of file - double expected