QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#135770#6302. MapSwarthmore#AC ✓6ms3852kbC++142.6kb2023-08-06 00:03:472023-08-06 00:03:50

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-06 00:03:50]
  • 评测
  • 测评结果:AC
  • 用时:6ms
  • 内存:3852kb
  • [2023-08-06 00:03:47]
  • 提交

answer

#include <cmath>
#include <iomanip>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long double ld;

const int maxn = 250;
const ld eps = 1e-10;


struct point {
  ld x,y;
  point (ld x_ = 0,ld y_ = 0){
      x = x_;
      y = y_;
  }
  point operator-(point a){
      return point(x-a.x,y-a.y);
  }
  point operator+(point a){
      return point(x+a.x,y+a.y);
  }
};

point operator*(ld k,point x){
    return point(x.x*k,x.y*k);
}

point u[maxn],v[maxn];
point r1[5],r2[5];

inline ld sqr(ld x){
    return x *x;
}

inline ld dist(point a,point b){
    return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y));
}

inline ld det(point u,point v){
    return u.x * v.y - u.y * v.x;
}

point solve(point u,point v,point x){
    ld d = det(u,v);
    return point(det(x,v) / d, det(u,x) / d);
}

point f(point x){
    // Solve linear system s * u + t * v == x
    point p = solve(r1[2] - r1[1],r1[4] - r1[1], x - r1[1]);
    return r2[1] + p.x * (r2[2] - r2[1]) + p.y * (r2[4] - r2[1]);
}

bool in_map(point x){
    point p = solve(r2[2] - r2[1],r2[4] - r2[1], x - r2[1]);
    return (p.x >= -eps && p.x <= 1 + eps && p.y >= -eps && p.y <= 1 + eps);
}

point f_inv(point x){
  point p = solve(r2[2] - r2[1],r2[4] - r2[1], x - r2[1]);
  return r1[1] + p.x * (r1[2] - r1[1]) + p.y * (r1[4] - r1[1]);
}

void solve(){
    for (int i = 1;i <= 4;i++){
        cin >> r1[i].x >> r1[i].y;
    }
    for (int i = 1;i <= 4;i++){
        cin >> r2[i].x >> r2[i].y;
    }
    point x,y;
    cin >> x.x >> x.y >> y.x >> y.y;
    ld k;
    int n;
    cin >> k >> n;
    u[n] = x;
    v[n] = y;
    for (int i = 1;i <= n;i++){
        u[n+i] = f(u[n+i-1]);
        v[n+i] = f(v[n+i-1]);
      //  printf("u[%d] = (%.3Lf,%.3Lf)\n",i, u[n+i].x,u[n+i].y);
      //  printf("v[%d] = (%.3Lf,%.3Lf)\n",i, v[n+i].x,v[n+i].y);

    }
    int last_u, last_v;
    last_u = n;
    last_v = n;
    for (int i = 0;i < n;i++){
        if (!in_map(u[n-i])){
            break;
        }
        u[n-i-1] = f_inv(u[n-i]);
        last_u--;
    }
    for (int i = 0;i < n;i++){
        if (!in_map(v[n-i])){
            break;
        }
        v[n-i-1] = f_inv(v[n-i]);
        last_v--;
    }
    ld opt = dist(x,y);
    for (int i = last_u;i <= 2*n;i++){
        for (int j = last_v;j <= 2*n;j++){
            if (abs(i-n) + abs(j-n) > n) continue;
            opt = min(opt, k * (abs(i-n) + abs(j-n)) + dist(u[i],v[j]));
        }
    }
    cout << opt << endl;
}

int main(){
    int t;
    cin >> t;
    cout << fixed << setprecision(11);
    while (t--){
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
0 0 0 2 4 2 4 0
0 0 0 1 2 1 2 0
2 1 4 2
1 1
0 0 0 3 6 3 6 0
0 1 1 0 3 2 2 3
0 0 4 2
0 3

output:

1.00000000000
1.22726233524

result:

ok 2 numbers

Test #2:

score: 0
Accepted
time: 5ms
memory: 3736kb

input:

100
-133 -128 -109 -134 -85 -38 -109 -32
-95 -37 -100 -35 -108 -55 -103 -57
-119 -130 -112 -44
2 73
5 -100 5 -8 1 -8 1 -100
1 -60 1 -14 3 -14 3 -60
3 -84 1 -20
2 53
-58 -78 -66 -78 -66 -34 -58 -34
-58 -34 -66 -34 -66 -78 -58 -78
-63 -50 -63 -37
4 54
52 -148 116 -148 116 -52 52 -52
53 -103 53 -71 101...

output:

9.50065749974
12.22973107892
13.00000000000
17.48853290038
13.34166406413
7.61577310586
23.40939982144
7.28010988928
21.28003773408
59.77602209258
4.12310562562
79.64923100696
65.06919393999
14.14213562373
41.82461550348
16.05624518490
15.67261752993
21.56220237420
66.27216610312
21.02379604163
20.8...

result:

ok 100 numbers

Test #3:

score: 0
Accepted
time: 5ms
memory: 3748kb

input:

100
-173 -113 -120 -113 -120 -115 -173 -115
-173 -115 -120 -115 -120 -113 -173 -113
-162 -114 -152 -114
99 57
6 23 -75 4 -56 -77 25 -58
0 -58 -51 -69 -62 -18 -11 -7
-22 -56 -42 -25
19 27
-98 -115 -150 -147 -158 -134 -106 -102
-150 -147 -98 -115 -106 -102 -158 -134
-103 -111 -136 -134
25 50
136 -92 1...

output:

10.00000000000
25.48363797558
40.22437072224
18.38477631085
9.21954445729
18.02775637732
43.11406302628
52.88704435235
45.54119014694
55.00099997500
37.00000000000
12.04159457879
24.33105012119
18.11077027627
7.56326275328
2.23606797750
8.23606797750
14.86476510887
6.32455532034
62.48732656691
37.65...

result:

ok 100 numbers

Test #4:

score: 0
Accepted
time: 3ms
memory: 3672kb

input:

100
-12 -206 72 -188 135 -482 51 -500
19 -301 23 -301 23 -315 19 -315
88 -368 28 -248
14 87
-221 -566 -467 -566 -467 -565 -221 -565
-221 -566 -467 -566 -467 -565 -221 -565
-297 -566 -289 -566
274 18
-264 759 -339 609 -129 504 -54 654
-208 580 -208 655 -103 655 -103 580
-196 664 -211 596
8 64
-111 -3...

output:

34.24695047554
8.00000000000
45.92695228684
135.11846653955
131.97348218487
40.34966595395
15.32134772871
77.77227503502
66.73881303590
8.00026665482
116.80644603167
12.58829001562
170.78563026629
131.96275042909
8.73808997516
17.46424919657
15.49965984287
26.06983614564
258.07363290348
17.745735329...

result:

ok 100 numbers

Test #5:

score: 0
Accepted
time: 4ms
memory: 3840kb

input:

100
-235 -704 133 -704 133 -720 -235 -720
-224 -712 -40 -712 -40 -704 -224 -704
15 -711 76 -718
4 74
-467 574 -475 596 -123 724 -115 702
-274 662 -270 652 -430 588 -434 598
-458 588 -241 657
15 31
380 -3 532 -343 787 -229 635 111
503 -71 639 -163 708 -61 572 31
533 -189 613 -137
3 58
-460 -7 -488 -7...

output:

31.35008143301
51.96763232094
21.46869792815
38.83793207647
84.24818742831
77.92945527848
47.00000000000
74.11549372591
86.46710488042
35.11409973216
3.60555127546
97.41663102366
24.60605696576
56.77335943272
6.99853461941
13.45362404707
150.78616572347
65.85590330411
26.17250465660
128.03515142335
...

result:

ok 100 numbers

Test #6:

score: 0
Accepted
time: 2ms
memory: 3836kb

input:

100
-1201 2822 -1197 2814 -3437 1694 -3441 1702
-3119 1860 -3117 1856 -1997 2416 -1999 2420
-1419 2709 -2491 2174
48 76
-2515 285 -2547 306 -1308 2194 -1276 2173
-2255 683 -2260 686 -2083 981 -2078 978
-1572 1753 -1392 2015
121 28
-1216 1209 -1498 -1141 -1598 -1129 -1316 1221
-1494 -823 -1494 -447 -...

output:

264.05586353288
290.42570045094
258.28240031307
743.73718476354
341.05278183882
400.56668366243
172.04079934096
27.77089460984
294.82588015208
508.06591068887
501.78182509932
666.80506896694
180.06943105369
193.61043360315
1507.00298606207
25.01999200639
81.74800749849
346.02898428973
105.4786686997...

result:

ok 100 numbers

Test #7:

score: 0
Accepted
time: 4ms
memory: 3792kb

input:

100
1411 -2755 603 -3563 623 -3583 1431 -2775
716 -3477 1120 -3073 1110 -3063 706 -3467
1210 -2959 1339 -2830
2319 39
4528 -3417 4286 -4055 1908 -3153 2150 -2515
2094 -2892 2094 -3090 2832 -3090 2832 -2892
2257 -2993 4389 -3736
17 22
-180 -1673 -2172 -3665 -2164 -3673 -172 -1681
-284 -1792 -2027 -35...

output:

182.43354954613
96.88092305393
530.33008588991
44.01136216933
64.31336536618
7.39289366613
34.56781020746
148.85016074299
350.33813591615
329.22516277982
68.86476510887
32.82438317461
244.69572942738
685.96883771198
141.36274799594
1601.78982672272
6.88559114617
70.67146070563
5.17965442927
277.0649...

result:

ok 100 numbers

Test #8:

score: 0
Accepted
time: 5ms
memory: 3668kb

input:

100
11928 -18111 8928 -17411 11056 -8291 14056 -8991
11043 -10811 10793 -10111 12921 -9351 13171 -10051
10491 -14092 11923 -12413
10 92
11869 -4371 3539 5429 1299 3525 9629 -6275
8302 -3064 3647 2571 4935 3635 9590 -2000
2384 2680 3466 2644
181 91
4001 -10187 4001 -10897 9 -10897 9 -10187
838 -10629...

output:

87.47965700263
977.20932282057
94.48632505936
307.00651458886
1245.62955970064
532.00000000000
369.04877726393
19.55402431723
1509.00000000000
275.09426721133
4242.19335151471
465.65625140881
3478.30424206018
1754.35600720036
1804.46692758593
21.35314266063
415.41553462457
1526.43440736902
3853.6029...

result:

ok 100 numbers

Test #9:

score: 0
Accepted
time: 2ms
memory: 3772kb

input:

100
10303 -4099 19487 -8131 19703 -7639 10519 -3607
18394 -7495 18842 -7271 18854 -7295 18406 -7519
15852 -6248 15950 -6389
38 10
13132 -3411 17416 3393 15634 4515 11350 -2289
13143 -873 15411 3411 16533 2817 14265 -1467
16515 2577 16017 1561
198 94
-5480 10872 -6297 11294 -11361 1490 -10544 1068
-1...

output:

84.57488648929
999.68927767813
6231.52966774611
550.94788609503
182.54412465861
5374.29679120906
825.72578109666
1653.20742916917
2777.10964853749
166.65302380610
1747.00457927276
651.11135760329
242.21000673227
34.26689584622
286.79086456859
2405.24662892058
2133.34221352318
1310.97813157377
48.466...

result:

ok 100 numbers

Test #10:

score: 0
Accepted
time: 6ms
memory: 3848kb

input:

100
0 -30 84 12 126 -72 42 -114
0 -30 84 12 126 -72 42 -114
91 -41 100 -55
96 93
168 110 148 150 48 100 68 60
48 100 68 60 168 110 148 150
61 96 102 90
8 2
-123 129 -60 174 -15 111 -78 66
-15 111 -78 66 -123 129 -60 174
-44 115 -104 132
27 3
27 42 15 54 -75 -36 -63 -48
-63 -48 -75 -36 15 54 27 42
-4...

output:

16.64331697709
41.43669871020
39.20655561573
11.18033988750
49.72926703663
26.92582403567
50.93132631299
10.29405582017
117.88553770501
8.60232526704
48.46648326421
21.09502310973
24.03840481041
16.00000000000
48.54894437575
26.06175685955
39.53983207834
10.77032961427
20.97321374946
7.28010988928
5...

result:

ok 100 numbers

Test #11:

score: 0
Accepted
time: 3ms
memory: 3748kb

input:

100
9725 6731 9725 11971 14965 11971 14965 6731
9725 6731 9725 11971 14965 11971 14965 6731
10293 11185 10445 9833
488 10
3833 -4831 6913 -4271 8443 -12686 5363 -13246
6913 -4271 3833 -4831 5363 -13246 8443 -12686
5209 -4960 7133 -6409
1 88
-5891 -6066 -8365 -6066 -8365 -8540 -5891 -8540
-8365 -6066...

output:

1360.51754858216
2119.67478013970
1638.60149419541
144.69968901141
1706.29921174453
2671.66801829868
1442.32485938501
2909.93127066603
5311.38635386280
7894.84420365595
2950.72143720820
1405.19727958717
8052.78597753597
436.08485412818
1910.19014712379
1597.00782715677
8923.07934515882
3776.23357328...

result:

ok 100 numbers

Test #12:

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

input:

100
1432065 -1359744 1432065 -1359796 610089 -1359796 610089 -1359744
610089 -1359744 610089 -1359796 1432065 -1359796 1432065 -1359744
1413145 -1359747 670086 -1359765
306 12
-630899 -570942 344981 -570942 344981 -567164 -630899 -567164
-630899 -567164 344981 -567164 344981 -570942 -630899 -570942
...

output:

41383.00394381265
344430.70876447704
597464.94716012226
57512.00002125128
180112.50498394934
254594.18946546365
13301.83436763094
246235.74134150387
17086.95373669631
168329.00118814939
580568.27843760117
120047.47596504528
24722.57593779418
252882.79871909042
366.88234114588
108187.76857333681
2882...

result:

ok 100 numbers

Test #13:

score: 0
Accepted
time: 2ms
memory: 3800kb

input:

100
-240497 1168822 -365542 931192 504344 473443 629389 711073
226221 683190 167481 688085 185400 903113 244140 898218
-192129 1110656 34450 941656
2 25
1729381 25950 1512625 519672 1528369 526584 1745125 32862
1536820 492965 1580974 388601 1584302 390009 1540148 494373
1660204 207517 1601591 344571...

output:

33.52377363915
126504.99951860885
57518.29369733295
318943.66370254168
169769.25000566879
1497.13389306735
23459.32499196507
853.34781609536
28.35141184590
7526.10652403645
36705.81656903984
575.01532167522
4025.08488222493
31458.02366646703
316549.01455698768
52928.37088934440
136396.39329148618
10...

result:

ok 100 numbers

Test #14:

score: 0
Accepted
time: 6ms
memory: 3852kb

input:

100
-889209 606569 -191736 1436894 638589 739421 -58884 -90904
-58884 -90904 638589 739421 -191736 1436894 -889209 606569
-486300 891465 -464854 988546
79 18
-1226546 957048 -712144 1926170 -590407 1861553 -1104809 892431
-712144 1926170 -1226546 957048 -1104809 892431 -590407 1861553
-807239 146415...

output:

99421.58456291068
404181.38882437425
311311.52891757799
271785.62453706046
319158.19183909411
77725.02554349505
103690.24156928994
33781.00427755220
16708.60835018883
262422.76822714907
176381.84309332976
159818.48394037531
451836.63422081362
291664.04018088780
406095.26661240463
591425.31798697965
...

result:

ok 100 numbers