QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#874467#8620. Jigsaw Puzzleucup-team6275WA 1ms4096kbC++204.7kb2025-01-28 06:34:292025-01-28 06:34:30

Judging History

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

  • [2025-01-28 06:34:30]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4096kb
  • [2025-01-28 06:34:29]
  • 提交

answer

#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <deque>
#include <set>
#include <cassert>
#include <cmath>
#include <complex>

using namespace std;
#define ld long double
#define cmpl complex<ld>

struct vec {
    ld x, y;

    ld len() {
        return sqrt(x * x + y * y);
    }

    vec() {}

    vec(ld x, ld y) : x(x), y(y) {}
};

vec operator-(const vec& a, const vec& b) {
    return {a.x - b.x, a.y - b.y};
}

vec operator+(const vec& a, const vec& b) {
    return {a.x + b.x, a.y + b.y};
}

ld operator*(const vec& a, const vec& b) {
    return a.x * b.x + a.y * b.y;
}

struct Side {
    ld len;
    int num;
    int ind;
};

bool cmp(const Side& a, const Side& b) {
    return a.len < b.len;
}

const ld EPS = 1e-9;

void transform_to_point(vector <vec>& a, int ind, vec flex) {
    vec adding = flex - a[ind];
    for (auto& i : a) {
        i = i + adding;
    }
}

void transform_mul(vector <vec>& a, int ind, cmpl value) {
    int n = a.size();
    vector <vec> flex(n);

    for (int i = 0; i < n; ++i) {
        int ii = (i + 1) % n;
        flex[i] = (a[ii] - a[i]);
    }

    for (int it = 0; it < n - 1; ++it) {
        int i = (ind + it) % n;
        int ii = (i + 1) % n;

        cmpl xd = {flex[i].x, flex[i].y};
        xd *= value;
        a[ii] = a[i] + vec(xd.real(), xd.imag());
    }
}

void solve() {
    int n;
    cin >> n;

    vector <vector <vec>> a(n);
    for (int i = 0; i < n; ++i) {
        int k;
        cin >> k;
        a[i].resize(k);
        for (int j = 0; j < k; ++j) {
            cin >> a[i][j].x >> a[i][j].y;
        }
    }

    vector <Side> sides;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < a[i].size(); ++j) {
            int jj = (j + 1) % a[i].size();
            sides.push_back({(a[i][jj] - a[i][j]).len(), i, j});
        }
    }
    sort(sides.begin(), sides.end(), cmp);
    map <pair <int, int>, vector <pair <int, int>>> g;

    for (int i = 0; i + 1 < sides.size(); ++i) {
        if (sides[i + 1].len - sides[i].len < EPS) {
            pair <int, int> t1 = {sides[i].num, sides[i].ind};
            pair <int, int> t2 = {sides[i + 1].num, sides[i + 1].ind};
            g[t1].push_back(t2);
            g[t2].push_back(t1);
        }
    }
    vector <int> used(n);
    vector <int> st;

    for (int i = 0; i < n; ++i) {
        int ln = a[i].size();
        for (int j = 0; j < a[i].size(); ++j) {
            vec vec1 = (a[i][(j + 1) % ln] - a[i][j]);
            vec vec2 = a[i][j] - (a[i][(j + ln - 1) % ln]);
            if (abs(vec1 * vec2) < EPS) {
                used[i] = 1;
                cmpl cha = {vec1.x, vec1.y};
                cha /= vec1.len();
                transform_mul(a[i], j, (cmpl)1 / cha);
                transform_to_point(a[i], j, vec(0, 0));
                used[i] = 1;
                st.push_back(i);
                break;
            }
        }
        if (!st.empty()) break;
    }

    while (!st.empty()) {
        int v = st.back();
        st.pop_back();

        int ln = a[v].size();
        for (int i = 0; i < ln; ++i) {
            int ii = (i + 1) % ln;

            for (auto [vv, j] : g[make_pair(v, i)]) {
                if (used[vv]) continue;
                vec vec1 = (a[v][ii] - a[v][i]);
                int jj = (j + 1) % a[vv].size();
                vec vec2 = (a[vv][jj] - a[vv][j]);
                cmpl need_vec = -cmpl(vec1.x, vec1.y) / cmpl(vec2.x, vec2.y);
                transform_mul(a[vv], j, need_vec);
                transform_to_point(a[vv], j, a[v][ii]);

                used[vv] = 1;
                st.push_back(vv);
            }
        }
    }

    for (int i = 0; i < n; ++i) {
        for (auto j : a[i]) {
            cout << fixed << setprecision(10) << j.x << " " << j.y << "\n";
        }
        cout << "\n";
    }
}

signed main() {
    if (1) {
        ios_base::sync_with_stdio(false);
        cin.tie(nullptr);
    }
    int32_t t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

/*
 4
4
0.440405375916 0.778474079786
0.000000000000 0.090337001520
0.469097990019 0.000000000000
0.702887505082 0.689470121906
4
0.222810526978 0.000000000000
0.270828246634 0.522212063829
0.000000000000 0.547114887265
0.021480010612 0.069880870008
4
0.000000000000 0.312825941471
0.358219176380 0.000000000000
0.532830100286 0.122181578260
0.088431750275 0.414089758021
4
0.158867722074 0.061734605990
0.973532298476 0.000000000000
0.853551564066 0.712811281737
0.000000000000 0.569141075980
 */

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
4
0.440405375916 0.778474079786
0.000000000000 0.090337001520
0.469097990019 0.000000000000
0.702887505082 0.689470121906
4
0.222810526978 0.000000000000
0.270828246634 0.522212063829
0.000000000000 0.547114887265
0.021480010612 0.069880870008
4
0.000000000000 0.312825941471
0.358219176380 0.00000...

output:

0.2771616363 0.0000000000
0.4732624314 0.7931166445
0.0000000000 0.7280292483
0.0000000000 0.0000000000

0.5244150465 1.0000000000
0.0000000000 1.0000000000
0.0000000000 0.7280292483
0.4732624314 0.7931166445

1.0000000000 1.0000000000
0.5244150465 1.0000000000
0.4732624314 0.7931166445
1.0000000000...

result:

ok OK

Test #2:

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

input:

2
4
1.187724454426 0.260257896229
0.903481480651 1.219010174901
0.000000000000 0.951153431795
0.309873903757 0.000000000000
4
0.516015116935 0.888042716318
0.000000000000 0.031046166652
0.048574738349 0.000000000000
0.587115596943 0.842599396881

output:

0.0000000000 0.0000000000
1.0000000000 -0.0000000000
1.0000000000 0.9423513255
0.0000000000 0.9156176942

0.0000000000 -0.0843823058
1.0000000000 -0.0576486745
1.0000000000 -0.0000000000
0.0000000000 0.0000000000


result:

wrong answer Double parameter [name=y] equals to -0.0843823, violates the range [-1e-06, 1]