QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#871515#8614. 3Ducup-team6275#TL 208ms4096kbC++234.2kb2025-01-25 20:57:432025-01-25 20:57:48

Judging History

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

  • [2025-01-25 20:57:48]
  • 评测
  • 测评结果:TL
  • 用时:208ms
  • 内存:4096kb
  • [2025-01-25 20:57:43]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rep(i, n) for (int i = 0; i < (n); i += 1)
#define len(a) ((int)(a).size())

mt19937_64 rnd(time(0));
mt19937 rndint(time(0) + 10);
const ll inf = 1e18;

const int SZ = 11;
const ld eps = 1e-9;
ld d[SZ][SZ];
int n;

struct pt {
    ld x, y, z;

    ld ln() {
        return sqrtl(x * x + y * y + z * z);
    }

    pt operator+(const pt &rht) {
        return {x + rht.x, y + rht.y, z + rht.z};
    }

    pt operator-(const pt &rht) {
        return {x - rht.x, y - rht.y, z - rht.z};
    }

    pt operator*(ld fuck) {
        return {x * fuck, y * fuck, z * fuck};
    }

    pt norm(ld a = 1) {
        ld nrm = a / ln();
        return {x * nrm, y * nrm, z * nrm};
    }
};
vector<pt> pts;

ld distsq(const pt &a, const pt &b) {
    return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) + (a.z - b.z) * (a.z - b.z);
}

ld dist(const pt &a, const pt &b) {
    return sqrtl(distsq(a, b));
}

ld get_random_ld() {
    const ll mod = 1e15;
    return rnd() % mod / (ld)(mod - 1);
}

int check(int v) {
    int res = 0;
    for (int i = 0; i < n; ++i) {
        if (i != v && abs(dist(pts[i], pts[v]) - d[i][v]) > 0.1 - eps)
            ++res;
    }
    return res;
}

int32_t main() {
    if (1) {
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }

    cin >> n;

#ifdef LOCAL
    vector<pt> genpts(n);
    for (int i = 0; i < n; ++i) {
        genpts[i].x = get_random_ld();
        genpts[i].y = get_random_ld();
        genpts[i].z = get_random_ld();
    }

    for (int i = 0; i < n; ++i) {
        d[i][i] = 0;
        for (int j = i + 1; j < n; ++j) {
            d[i][j] = dist(genpts[i], genpts[j]) - (get_random_ld() - 0.5) / 5;
            d[j][i] = d[i][j];
        }
    }

#else
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j)
            cin >> d[i][j];
    }
#endif

    while (true) {
        pts.resize(n);
        vector<vector<ld>> ws(n, vector<ld>(n));
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                ws[i][j] = get_random_ld() + 5;
            }
        }
        for (int i = 0; i < n; ++i) {
            pts[i].x = get_random_ld();
            pts[i].y = get_random_ld();
            pts[i].z = get_random_ld();
        }

        int cnt_bad = 0;
        for (int i = 0; i < n; ++i)
            cnt_bad += check(i);

        cnt_bad /= 2;
        int iters = 0;

        bool fail = false;
        while (cnt_bad) {
            int v = rndint() % n;
            cnt_bad -= check(v);
            pt cur = {0, 0, 0};
            ld normed = 0;
            for (int i = 0; i < n; ++i) {
                if (i == v)
                    continue;

                pt yp = pts[i] + (pts[v] - pts[i]).norm(d[v][i]);

                cur = cur + yp * ws[i][v];
                normed += ws[i][v];
            }
            cur = cur * (1 / normed);
            pts[v] = cur;
            cnt_bad += check(v);

            if (iters % 100 == 0) {

                cnt_bad = 0;
                for (int i = 0; i < n; ++i) {
                    cnt_bad += check(i);
                }
                cnt_bad /= 2;
            }

            ++iters;
            if (iters >= 50000) {
                fail = true;
                break;
            }
        }

        if (fail)
            continue;

#ifdef LOCAL
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                cout << setprecision(10) << fixed << dist(pts[i], pts[j]) << " ";
            }
            cout << "\n";
        }
#endif

        pt avg = {0, 0, 0};
        for (auto c : pts) {
            avg = avg + c;
        }
        avg.x /= n;
        avg.y /= n;
        avg.z /= n;

        for (auto c : pts) {
            c = c - avg;
            cout << setprecision(20) << fixed << c.x << " " << c.y << " " << c.z << "\n";
        }
        break;
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
0.000000 0.758400 0.557479 0.379026
0.758400 0.000000 0.516608 0.446312
0.557479 0.516608 0.000000 0.554364
0.379026 0.446312 0.554364 0.000000

output:

0.25445504666716985619 -0.16939137718752523317 -0.22726231927303262341
-0.26143092849210430471 0.03309709802196345100 0.22410749939507545184
-0.07014193433811168927 0.35927172772270476233 -0.08585480347084188443
0.07711781616304613795 -0.22297744855714298019 0.08900962334879905603

result:

ok OK. Max delta: 0.078794

Test #2:

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

input:

1
0.000000

output:

0.00000000000000000000 0.00000000000000000000 0.00000000000000000000

result:

ok OK. Max delta: 0.000000

Test #3:

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

input:

2
0.000000 0.938096
0.938096 0.000000

output:

0.19170047959496078725 -0.08134259896992707774 0.42028601454233477879
-0.19170047959496078723 0.08134259896992707774 -0.42028601454233477879

result:

ok OK. Max delta: 0.000000

Test #4:

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

input:

3
0.000000 0.769195 0.308169
0.769195 0.000000 0.686850
0.308169 0.686850 0.000000

output:

0.10672056290879934550 -0.23018522833870822176 -0.14676484382582916170
-0.36162865148296008589 0.11266365490383980965 0.29200055631563221696
0.25490808857416074039 0.11752157343486841214 -0.14523571248980305537

result:

ok OK. Max delta: 0.069802

Test #5:

score: 0
Accepted
time: 0ms
memory: 3968kb

input:

5
0.000000 0.444506 0.292333 0.209539 1.195824
0.444506 0.000000 0.220873 0.748833 0.757486
0.292333 0.220873 0.000000 0.533499 0.797167
0.209539 0.748833 0.533499 0.000000 1.141148
1.195824 0.757486 0.797167 1.141148 0.000000

output:

-0.29590795642317880624 -0.09812629970796835606 -0.16592654758932293385
-0.05426362494744047194 0.31816080788491265890 0.03487451500618747190
-0.04235334428417888503 0.12272540996104296145 -0.11486897585851411132
-0.30733842545220405507 -0.34057437233301738716 -0.03610157929010324195
0.6998633511070...

result:

ok OK. Max delta: 0.099729

Test #6:

score: 0
Accepted
time: 0ms
memory: 3968kb

input:

6
0.000000 0.932377 0.787009 0.996894 0.763544 0.651377
0.932377 0.000000 0.421278 1.155673 1.149686 0.508563
0.787009 0.421278 0.000000 0.709021 0.793974 0.224884
0.996894 1.155673 0.709021 0.000000 0.392548 0.957498
0.763544 1.149686 0.793974 0.392548 0.000000 0.714079
0.651377 0.508563 0.224884 0...

output:

0.01611868390933300893 0.57704973674247098873 -0.04133442784513671194
0.57274526423192822854 -0.17960100163510019013 0.15169345424783119489
0.18436713118062616915 -0.17433609810511086616 -0.18344472333826297196
-0.54896032489729077071 -0.29228645052915071159 0.03037403667972799477
-0.479802859556391...

result:

ok OK. Max delta: 0.091736

Test #7:

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

input:

7
0.000000 0.688481 0.455407 0.777049 0.963980 0.255052 0.554599
0.688481 0.000000 0.596921 0.827787 1.260207 0.340235 0.493011
0.455407 0.596921 0.000000 0.609173 0.640567 0.352193 0.243913
0.777049 0.827787 0.609173 0.000000 0.858134 0.701131 0.393303
0.963980 1.260207 0.640567 0.858134 0.000000 0...

output:

-0.07177940660349307200 0.14376272049458525294 0.37061161352253304947
-0.27487863052238330474 -0.43509671205706535005 0.14241045057995274859
-0.03394582967776463040 0.07141756596527400560 -0.09136558374577389367
0.49061512923083566419 -0.09621686100435553946 -0.07052636809105314506
-0.05419591011904...

result:

ok OK. Max delta: 0.091702

Test #8:

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

input:

8
0.000000 0.437494 0.934265 0.074097 0.673669 0.425700 0.479212 0.679270
0.437494 0.000000 0.331045 0.393801 0.527073 0.402792 0.375134 0.461133
0.934265 0.331045 0.000000 0.792317 0.605663 0.880433 0.786178 0.455534
0.074097 0.393801 0.792317 0.000000 0.681633 0.278020 0.327267 0.550058
0.673669 0...

output:

0.31611961881276567075 0.17820262050853122676 -0.08935471771268732434
-0.06090753282684496705 -0.09443862865410731670 0.07692791047013678427
-0.12272777352011276193 -0.44247935988813084978 0.28814457258860058842
0.20493410604278451491 0.12559698348707580223 -0.12543605307594343342
-0.106968386091096...

result:

ok OK. Max delta: 0.099151

Test #9:

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

input:

9
0.000000 0.883128 0.449200 0.525234 0.745161 0.323207 0.430759 1.247103 0.564870
0.883128 0.000000 0.664206 0.590150 0.433578 0.890708 0.741718 0.798316 1.033522
0.449200 0.664206 0.000000 0.326949 0.636800 0.523900 0.642051 0.680925 0.349474
0.525234 0.590150 0.326949 0.000000 0.523965 0.344241 0...

output:

-0.13094706092220827917 -0.06023080562520691860 0.42741533114953384509
0.44139810621580629631 -0.07997042381154812602 -0.30411261886210452785
-0.20051684040184083378 0.06178962840743341983 -0.06355595909016030718
-0.05738839134152191949 -0.23782430236669469212 -0.00185586290351522038
0.4309967870457...

result:

ok OK. Max delta: 0.099042

Test #10:

score: 0
Accepted
time: 0ms
memory: 3968kb

input:

10
0.000000 1.141963 0.357381 0.960442 0.887799 0.393165 1.000015 0.883861 1.059968 0.666258
1.141963 0.000000 0.730979 0.430440 0.528721 0.822481 0.567380 0.334929 0.552413 0.840500
0.357381 0.730979 0.000000 0.861027 0.623726 0.216981 0.719423 0.558824 0.726378 0.310217
0.960442 0.430440 0.861027 ...

output:

0.32960276095938683219 -0.44189791045657463863 0.36627840478284911372
-0.30709008603221083075 0.30168080395870908717 -0.19859407195536100985
0.27135197786609716687 -0.13944394386745783521 0.12448476511423253315
-0.44301266628939145182 -0.18292119474593378582 -0.22283341765207383070
-0.20762402662479...

result:

ok OK. Max delta: 0.099833

Test #11:

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

input:

10
0.000000 0.508467 0.359704 0.705660 0.752608 0.632298 0.433047 0.541855 0.108842 0.652503
0.508467 0.000000 0.849608 0.542157 0.614068 0.673963 0.552462 0.470005 0.697815 0.822930
0.359704 0.849608 0.000000 0.832286 0.790254 0.844729 0.428335 0.707356 0.221649 0.447522
0.705660 0.542157 0.832286 ...

output:

0.22870871035418678679 -0.15272737049118691817 -0.02936052802710432132
-0.28811100110610904484 -0.29773842902204380120 0.13077515432224707593
0.37385525562998691337 0.13169324766629521384 -0.18357324502730613117
-0.43949127169888305426 0.15479767930212447259 -0.04666942239682644091
-0.20148553848886...

result:

ok OK. Max delta: 0.099590

Test #12:

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

input:

10
0.000000 0.532841 1.081715 0.791902 0.304710 0.943952 0.318604 0.512618 0.263399 0.317304
0.532841 0.000000 0.617254 0.571776 0.863445 0.644868 0.534570 0.898453 0.767957 0.380512
1.081715 0.617254 0.000000 0.498716 1.118400 0.375946 0.739541 1.081104 0.985516 0.778030
0.791902 0.571776 0.498716 ...

output:

-0.04130917603952689426 0.10635823473930963986 0.35778391314778022688
-0.28520371593923588748 -0.31918380652402442439 0.05695215159946286053
-0.03493648570042649846 -0.55948513087141397575 -0.37639948148473443158
0.05303660692530581388 -0.14183727960002210317 -0.42260082124376608151
0.04526974786119...

result:

ok OK. Max delta: 0.099873

Test #13:

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

input:

10
0.000000 0.337812 0.820740 0.714576 0.958294 1.114603 1.052855 0.816204 0.921684 0.581533
0.337812 0.000000 0.588126 0.550959 0.851936 1.076003 0.824637 0.634512 0.630209 0.781504
0.820740 0.588126 0.000000 0.754545 0.853344 0.651402 0.625435 0.521290 0.463145 0.927492
0.714576 0.550959 0.754545 ...

output:

-0.42795731428099172730 0.01869996938774792366 0.44781169458045206054
-0.18851495697438634300 -0.16635028114272663252 0.37673400553815716379
0.17039189468064199926 -0.39569459761671501476 0.05779473618444354789
-0.47930697789190574657 -0.09548454465044944889 -0.18436285245155390181
0.326979310513168...

result:

ok OK. Max delta: 0.099243

Test #14:

score: 0
Accepted
time: 208ms
memory: 3968kb

input:

10
0.000000 0.157221 0.630350 0.940948 0.790907 0.666502 0.536584 0.506196 0.353744 0.642539
0.157221 0.000000 0.582092 1.279081 0.812532 0.810677 0.850103 0.865478 0.320962 0.694578
0.630350 0.582092 0.000000 1.171965 1.045437 1.168568 0.582206 0.854963 0.513105 1.137099
0.940948 1.279081 1.171965 ...

output:

-0.03640403154812643148 -0.19119365727003691688 -0.23779841852341051563
-0.20864649733640288793 -0.22945301645470072134 -0.41560178018980416354
-0.33256536321254166587 -0.59445830835290073202 0.05666100318981751879
0.41864521378756943819 0.13279077473978938810 0.59620584756519003620
-0.1328154109314...

result:

ok OK. Max delta: 0.094848

Test #15:

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

input:

10
0.000000 0.655953 0.416075 0.956128 0.351321 0.411663 0.904277 0.786858 0.961004 1.159073
0.655953 0.000000 0.398507 0.430374 0.378366 0.531641 0.789955 0.396050 0.368849 1.088933
0.416075 0.398507 0.000000 0.976294 0.461240 0.328488 0.979923 0.705916 0.884932 1.254989
0.956128 0.430374 0.976294 ...

output:

0.01747955608881463164 -0.44054946925667082432 0.33030615236158084440
0.18207321865929093364 0.10098218680307965287 0.16559138398841317499
0.38104942723388471657 -0.32301726858101272838 0.20829020503116096576
-0.06121041252436948817 0.46046260005184222445 0.09016582105796482901
0.0323483934801819299...

result:

ok OK. Max delta: 0.099195

Test #16:

score: 0
Accepted
time: 0ms
memory: 3968kb

input:

10
0.000000 0.672245 0.576475 0.810904 0.599396 0.493165 0.431514 0.511677 0.859634 0.881368
0.672245 0.000000 1.249406 1.027657 0.113558 0.392208 0.862698 0.329856 1.012059 1.039747
0.576475 1.249406 0.000000 0.869439 1.254676 1.087547 0.535956 1.182094 0.744887 0.645939
0.810904 1.027657 0.869439 ...

output:

0.29516740432416963534 -0.12098818228897677770 0.10049765400395808852
-0.26803252839708005713 -0.28487036712711322683 0.40917862529416437203
0.52515973275153568414 0.14107453899570810956 -0.45926955453294072263
-0.14804920006843779918 0.50358843296278383347 -0.18202002986453422531
-0.267153174524872...

result:

ok OK. Max delta: 0.097982

Test #17:

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

input:

10
0.000000 0.609276 0.612588 0.898616 0.668529 0.802163 0.126104 0.681054 0.761434 0.310892
0.609276 0.000000 0.922363 0.423227 0.591390 0.662160 0.751720 0.241917 0.563127 0.693959
0.612588 0.922363 0.000000 0.873479 0.681583 0.707351 0.595097 0.923846 0.768951 0.393683
0.898616 0.423227 0.873479 ...

output:

-0.16892532004261331163 -0.26490966562686478499 0.35789943912350633047
-0.40969229813501801543 0.03130887949448700355 -0.18493994356851112547
0.43768491480101683402 -0.35724755264065317394 0.13729801405477066759
-0.04305054745945880872 0.28622789663602068097 -0.31054222964274926587
0.100149026737108...

result:

ok OK. Max delta: 0.097548

Test #18:

score: -100
Time Limit Exceeded

input:

10
0.000000 0.542508 0.426558 0.741404 0.733105 0.586307 0.271270 0.847645 0.757695 0.830800
0.542508 0.000000 0.497136 1.012191 1.083431 0.944439 0.618287 0.696705 0.472089 0.354373
0.426558 0.497136 0.000000 0.973354 0.928175 0.884683 0.594828 0.699473 0.534409 0.737409
0.741404 1.012191 0.973354 ...

output:


result: