QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#577229#8081. Minimum Manhattan Distancexinhuo2005AC ✓156ms3936kbC++171.4kb2024-09-20 09:27:502024-09-20 09:27:51

Judging History

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

  • [2024-09-20 09:27:51]
  • 评测
  • 测评结果:AC
  • 用时:156ms
  • 内存:3936kb
  • [2024-09-20 09:27:50]
  • 提交

answer

#include<bits/stdc++.h>
using ll = long long;
const int mod = 998244353;
#define pdd std::pair<double, double> 
#define db double
#define x first
#define y second

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

db dis(pdd a, pdd b) {
    pdd c = a - b;
    return sqrt(c.x * c.x + c.y * c.y);
}

void solve() {
    db x1l, y1l, x1r, y1r;
    db x2l, y2l, x2r, y2r;
    std::cin >> x1l >> y1l >> x1r >> y1r >> x2l >> y2l >> x2r >> y2r;
    pdd o1 = {(x1l + x1r) / 2, (y1l + y1r) / 2};
    pdd o2 = {(x2l + x2r) / 2, (y2l + y2r) / 2};
    
    db r1 = dis({x1l, y1l}, {x1r, y1r}) / 2;
    db r2 = dis({x2l, y2l}, {x2r, y2r}) / 2;
    db T = sqrt(2);
    std::cout << std::fixed << std::setprecision(15);
    if (o1.x > o2.x && o1.y > o2.y) {
        std::cout << o1.x + o1.y - (o2.x + o2.y + T * r2) << "\n";
    } 
    else if (o1.x < o2.x && o1.y < o2.y) {
        std::cout << o2.x + o2.y - T * r2 - (o1.x + o1.y) << "\n";
    }
    else if (o1.x < o2.x && o1.y > o2.y) {
        std::cout << (o1.y - o1.x) - (o2.y - o2.x + T * r2) << "\n";
    }
    else {
        std::cout << o2.y - o2.x - T * r2 - (o1.y - o1.x) << "\n";
    }
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int t = 1;
    std::cin >> t;

    while (t--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1
0 0 2 1
4 5 5 2

output:

4.263932022500210

result:

ok Your answer is acceptable!^ ^

Test #2:

score: 0
Accepted
time: 155ms
memory: 3808kb

input:

100000
64184 -33682 59295 3067
16568 83379 -30901 17899
4747 16156 33365 80028
-41011 -93961 -89583 -95743
96914 -33206 12828 -88885
-93518 29681 -82022 42270
40225 76998 25677 84480
66361 -32945 94822 -81258
-17979 41800 -91442 80586
40229 -78184 30070 -89624
-21082 -94587 48262 -87979
-95197 91518...

output:

77664.492686403216794
192928.302701440668898
227607.106035306642298
145831.444580046052579
224138.523189468862256
203168.416322626173496
106258.702187296643388
114459.030348488973686
130191.378343408272485
92639.995133674121462
110927.182439468233497
121482.255326366721420
130471.051428038903396
193...

result:

ok Your answer is acceptable!^ ^

Test #3:

score: 0
Accepted
time: 152ms
memory: 3832kb

input:

100000
-18320 -12065 -63211 -70160
25465 23684 51590 90971
320 47201 7943 81396
-92700 -32637 -74486 -4692
99421 19908 91756 -28366
25529 -55621 18271 -78859
27654 -68417 31755 -96497
-26728 -28568 -50384 -393
-10805 -86093 7305 -27809
-64498 85696 -76254 19562
84518 11339 26149 17948
2447 55045 -13...

output:

126693.525110459857387
147100.715342060721014
119484.924663965706713
110223.186736658535665
130709.108038525300799
92808.270238245109795
118867.001846637722338
297697.871129691135138
213765.602167080854997
90968.357807112013688
165745.367435086431215
184370.169144306099042
184241.466886319918558
132...

result:

ok Your answer is acceptable!^ ^

Test #4:

score: 0
Accepted
time: 156ms
memory: 3888kb

input:

100000
37495 80384 -22610 56295
-62653 -47270 -62203 -6381
-86440 63964 25226 91598
62192 -71344 39815 -45590
-81947 13219 -50302 92935
70951 -12452 44060 -68999
68612 -63329 67331 -30225
21098 36822 -86721 85311
14179 56408 37664 -10185
-71446 -35104 -83185 -35928
62231 49184 -22420 -2128
-38074 -9...

output:

136120.859927884273930
193733.837878013728186
173156.721689506113762
125031.883301315378048
153543.349328368087299
166748.475858951976988
185481.061734316288494
177488.089643897721544
108138.479897402197821
180039.829205497138901
161614.879860872373683
157287.764510839304421
153821.044120484875748
6...

result:

ok Your answer is acceptable!^ ^

Test #5:

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

input:

100000
29660 -79759 63721 -76194
73610 -35151 84824 -12411
-87524 -63981 -79091 -72979
2216 18174 -8275 -10477
43042 -7367 6840 -22825
-37089 39403 -11737 74216
-38578 -60298 -11315 -54231
-74974 27413 -80834 23157
54452 -75442 29525 -46682
-90307 -93765 -98254 -98119
-89611 -83470 -51787 -86428
527...

output:

68793.511552838594071
131031.736015195900109
90807.333632071429747
130385.811856609827373
164741.499512290291023
265321.883756267721765
164666.598904132377356
86404.234193280382897
199326.169497080292786
86550.267561678469065
120915.381618065555813
124345.837935445480980
214598.283823960839072
14347...

result:

ok Your answer is acceptable!^ ^

Test #6:

score: 0
Accepted
time: 147ms
memory: 3936kb

input:

100000
-559 -590 -265 -338
671 670 -34 551
266 -278 -592 281
958 638 806 872
-34 809 -373 949
380 -847 962 -208
863 -691 927 578
-730 -913 -793 -956
-88 -133 -470 74
726 -585 769 -641
143 -383 -500 -361
836 580 434 512
-103 -967 554 -855
-226 383 -760 -57
920 749 626 979
202 392 -661 -403
-505 315 -...

output:

1299.437936549823917
1601.193132405382357
1669.835128627307313
2480.564853759352900
1560.075056334533429
1443.205012183701001
1303.237289383300777
1042.303067379419417
2227.792555225992601
1408.928718704054745
1608.750106929018784
1105.600487276986314
1662.585458445455515
868.075300957536001
1995.47...

result:

ok Your answer is acceptable!^ ^

Test #7:

score: 0
Accepted
time: 140ms
memory: 3828kb

input:

100000
20 -100 98 -47
-10 21 -100 92
26 5 23 45
-48 -22 -13 -33
85 -56 88 -92
3 26 -100 -16
90 39 53 -1
17 -55 -67 -75
-88 31 -99 14
-58 -12 -64 -10
-76 -17 -46 -79
-13 92 77 56
95 -73 19 -34
-46 38 -5 4
20 -43 79 -4
-76 84 -41 89
-58 -38 -15 -55
-97 21 -76 23
-70 -78 -32 -46
70 91 50 -18
84 -91 100...

output:

162.941379236999097
81.557756457854310
135.345693061345969
119.442649910105004
61.527864045000420
146.458042047224808
119.337020829467036
193.000000000000000
103.583566109823693
131.138657489805610
186.915072127435394
187.308281641358320
160.392049369441054
89.279981273412346
99.144009233240723
105....

result:

ok Your answer is acceptable!^ ^

Test #8:

score: 0
Accepted
time: 130ms
memory: 3828kb

input:

100000
2 7 -6 8
-9 -5 -10 -7
2 4 2 8
-3 -10 -10 -2
4 0 -3 -2
8 -7 8 -10
-7 4 -3 -4
8 -7 8 -10
-10 4 2 4
8 -10 8 -7
4 1 5 6
-7 -4 -10 -4
8 1 6 5
-1 -8 -7 -3
-9 5 -6 8
2 -1 3 -2
-9 4 -10 7
6 -9 8 -1
-1 -4 3 -4
-10 -8 -7 -10
10 2 4 4
0 -7 -4 -4
-10 2 -7 8
4 -10 -1 -3
-9 -4 -6 -5
-1 2 8 4
1 8 -4 8
-7 -1...

output:

19.418861169915811
12.983351810813545
12.878679656440358
19.378679656440358
22.378679656440358
18.378679656440358
13.977319491406369
17.000000000000000
21.169048105154701
11.950490243203607
13.964466094067262
15.417237469701780
11.980797594797352
22.263932022500210
13.257359312880714
21.950490243203...

result:

ok Your answer is acceptable!^ ^

Extra Test:

score: 0
Extra Test Passed