QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#715117#8082. Minimum Euclidean Distanceqzez#AC ✓389ms4040kbC++141.8kb2024-11-06 10:30:332024-11-06 10:30:34

Judging History

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

  • [2024-11-06 10:30:34]
  • 评测
  • 测评结果:AC
  • 用时:389ms
  • 内存:4040kb
  • [2024-11-06 10:30:33]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const double eps=1e-6;
double r,d;
double f(double x){
    return 2*sqrt(max(0.0,r*r-x*x))*(x-d)*(x-d);
}
double calc(double l,double r){
    return (r-l)*(f(l)+f(r)+4*f((l+r)/2))/6;
}
double solve(double l,double r,double eps,double ans,int d=8){
    // fprintf(stderr,"%lf %lf %lf %lf\n",l,r,eps,ans);
    double mid=(l+r)/2,fl=calc(l,mid),fr=calc(mid,r);
    if(abs(fl+fr-ans)<eps*15*max(1.0,ans))return fl+fr+(fl+fr-ans)/15;
    return solve(l,mid,eps,fl,d-1)+solve(mid,r,eps,fr,d-1);
}
using vec=complex<ll>;
const int N=5e3+10;
vec a[N];
ll dot(vec a,vec b){
    return real(a)*real(b)+imag(a)*imag(b);
}
ll cross(vec a,vec b){
    return dot(a,b*vec(0,-1));
}
ll dis2(vec a){
    return dot(a,a);
}
int n,m;
void read(vec &a){
    static ll x,y;
    scanf("%lld%lld",&x,&y);
    a=vec(x*2,y*2);
}
bool isin(vec o){
    for(int i=1;i<=n;i++){
        if(cross(o-a[i],a[i%n+1]-a[i])>0)return 0;
    }
    return 1;
}
double calc(vec a,vec b,vec x){
    if(dot(x-a,b-a)<0)return sqrt(dis2(x-a));
    if(dot(x-b,a-b)<0)return sqrt(dis2(x-b));
    return abs(cross(x-a,x-b))/sqrt(dis2(a-b));
}
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1,x,y;i<=n;i++){
        read(a[i]);
    }
    for(;m--;){
        vec s,t;
        read(s),read(t);
        vec cur=s-t;
        double x=real(cur),y=imag(cur);
        r=sqrt(x*x+y*y)/2;
        vec o=(s+t)/2ll;
        if(!isin(o)){
            d=INFINITY;
            for(int i=1;i<=n;i++){
                d=min(d,calc(a[i],a[i%n+1],o));
            }
        }else d=0;
        d/=sqrt(2);
        // cerr<<r<<' '<<d<<endl;
        double ans=solve(-r,r,eps,calc(-r,r));
        ans*=2;
        static const double pi=acos(-1);
        ans/=pi*r*r;
        printf("%.9lf\n",ans/4);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

0.249999486
0.749999251
1.874999601

result:

ok Your answer is acceptable!^ ^

Test #2:

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

input:

48 10
-30 0
-29 -4
-28 -7
-27 -9
-25 -12
-22 -16
-21 -17
-17 -20
-14 -22
-12 -23
-9 -24
-5 -25
-4 -25
0 -24
3 -23
5 -22
8 -20
12 -17
13 -16
16 -12
18 -9
19 -7
20 -4
21 0
21 1
20 5
19 8
18 10
16 13
13 17
12 18
8 21
5 23
3 24
0 25
-4 26
-5 26
-9 25
-12 24
-14 23
-17 21
-21 18
-22 17
-25 13
-27 10
-28 ...

output:

589.499992982
51.470587413
1051.249986022
66.624999110
174.124998683
562.674996016
272.394226990
287.384996660
689.624990831
436.249994199

result:

ok Your answer is acceptable!^ ^

Test #3:

score: 0
Accepted
time: 344ms
memory: 4020kb

input:

5000 5000
-50000000 0
-49999885 -49450
-49999770 -85675
-49999604 -122394
-49999391 -157604
-49999130 -192731
-49998803 -229143
-49998399 -267196
-49997956 -303872
-49997469 -339362
-49996891 -377221
-49996257 -414903
-49995577 -451819
-49994843 -488600
-49994059 -524941
-49993173 -563137
-49992252 ...

output:

2214785319995240.250000000
1632645093224570.000000000
3954739919951974.000000000
5405105625972459.000000000
817274710112999.750000000
902260838421701.500000000
3194363118976392.000000000
1619744424788273.000000000
363457480589296.687500000
4776425494202331.000000000
8267595346673804.000000000
246716...

result:

ok Your answer is acceptable!^ ^

Test #4:

score: 0
Accepted
time: 283ms
memory: 3992kb

input:

2224 5000
-500000 0
-499999 -30
-499998 -59
-499997 -87
-499996 -114
-499995 -140
-499994 -165
-499993 -189
-499992 -212
-499991 -234
-499990 -255
-499989 -275
-499988 -294
-499987 -312
-499986 -329
-499985 -345
-499984 -360
-499982 -389
-499981 -403
-499979 -430
-499978 -443
-499976 -468
-499975 -4...

output:

931340781062.895629883
410570461048.611389160
225774973075.329956055
686588106798.562377930
803635156587.432006836
440321802987.473937988
781364858103.348999023
303496621381.181457520
146653886324.610504150
1361017629660.519042969
409649024429.427124023
417747455916.182556152
465091806986.187316895
...

result:

ok Your answer is acceptable!^ ^

Test #5:

score: 0
Accepted
time: 93ms
memory: 4028kb

input:

4672 5000
-300 0
-299 -43
-298 -85
-297 -126
-296 -166
-295 -205
-294 -243
-293 -280
-292 -316
-291 -351
-290 -385
-289 -418
-288 -450
-287 -481
-286 -511
-285 -540
-284 -568
-283 -595
-282 -621
-281 -646
-280 -670
-279 -693
-278 -715
-276 -758
-275 -779
-273 -820
-272 -840
-270 -879
-269 -898
-267 ...

output:

356616.495258429
121018.498390939
0.249999486
189.624997477
103099.623629188
83253.123893067
131701.248248901
58352.499224146
355863.120268446
197638.857377759
605772.407081328
2062.445873278
113763.248487405
134694.498209103
74679.651034480
114481.248477858
60577.249194565
7456.249900862
44460.2494...

result:

ok Your answer is acceptable!^ ^

Test #6:

score: 0
Accepted
time: 39ms
memory: 3972kb

input:

576 5000
-300 0
-299 -15
-298 -29
-297 -42
-296 -54
-295 -65
-294 -75
-293 -84
-292 -92
-290 -107
-289 -114
-287 -127
-286 -133
-284 -144
-283 -149
-280 -163
-278 -172
-275 -185
-274 -189
-270 -204
-267 -215
-265 -222
-262 -232
-258 -245
-257 -248
-252 -262
-248 -273
-245 -281
-240 -294
-238 -299
-2...

output:

189295.247483132
377943.290820753
299472.996018209
243821.913237037
559270.979566907
100367.590915903
472743.118714410
374450.620021307
77260.623972743
106891.229557227
193578.122426187
98895.064437063
124019.998351031
296138.868224695
1209.124983923
480040.618617383
133543.967590756
194310.99867476...

result:

ok Your answer is acceptable!^ ^

Test #7:

score: 0
Accepted
time: 24ms
memory: 3952kb

input:

336 5000
-300 0
-299 -11
-298 -21
-297 -30
-296 -38
-295 -45
-294 -51
-292 -62
-291 -67
-289 -76
-288 -80
-285 -91
-283 -98
-280 -108
-279 -111
-275 -122
-272 -130
-270 -135
-267 -142
-263 -151
-258 -162
-257 -164
-251 -175
-246 -184
-242 -191
-239 -196
-234 -204
-227 -215
-225 -218
-218 -228
-213 -...

output:

478.124993642
408.124994573
1341.249982167
861.249988549
4209.999944024
1709.124977275
846.249988748
1389.124981530
722.499990393
753.124989986
574.249992365
1167.124984482
439.624994154
5650.249924874
619.624991761
2664.499964573
2138.624971565
2138.624971565
1226.249983696
1226.249983696
702.12499...

result:

ok Your answer is acceptable!^ ^

Test #8:

score: 0
Accepted
time: 29ms
memory: 3900kb

input:

336 5000
-300 0
-299 -11
-298 -21
-297 -30
-296 -38
-295 -45
-294 -51
-292 -62
-291 -67
-289 -76
-288 -80
-285 -91
-283 -98
-280 -108
-279 -111
-275 -122
-272 -130
-270 -135
-267 -142
-263 -151
-258 -162
-257 -164
-251 -175
-246 -184
-242 -191
-239 -196
-234 -204
-227 -215
-225 -218
-218 -228
-213 -...

output:

95.124998733
8382.624888545
77361.123971407
142408.123106542
98056.248696245
110581.248529712
20412.999728589
1253.124983338
64468.624142826
8915.624881458
93179.123761091
26286.249650498
35118.249533068
129681.248275759
59545.624208282
49997.910036715
1685.124977595
58020.624228558
38371.999489806
...

result:

ok Your answer is acceptable!^ ^

Test #9:

score: 0
Accepted
time: 389ms
memory: 3964kb

input:

5000 5000
-50000000 0
-49999912 -33572
-49999824 -59400
-49999710 -83347
-49999578 -105149
-49999382 -130924
-49999166 -154591
-49998916 -178069
-49998599 -203894
-49998262 -228398
-49997905 -251647
-49997466 -277451
-49997003 -302413
-49996511 -326907
-49995964 -352128
-49995393 -376671
-49994795 -...

output:

481990662207307584.000000000
900047237634445568.000000000
84250234110065744.000000000
357963468567098880.000000000
758024693246050944.000000000
651805785326792960.000000000
422072210734237696.000000000
571948900402193920.000000000
685946944019449728.000000000
781017515236944640.000000000
39263911969...

result:

ok Your answer is acceptable!^ ^

Test #10:

score: 0
Accepted
time: 384ms
memory: 4040kb

input:

5000 5000
-50000000 0
-49999762 -138397
-49999461 -244153
-49999007 -349713
-49998392 -456086
-49997577 -566637
-49996632 -673023
-49995462 -784273
-49994137 -894156
-49992625 -1005080
-49990945 -1115094
-49989066 -1226720
-49987021 -1337531
-49984788 -1449227
-49982415 -1559155
-49979887 -1668061
-...

output:

259053254439763872.000000000
472297856245316608.000000000
271976520634996896.000000000
930648874351885696.000000000
110596171749029760.000000000
385963657035242048.000000000
441658535484969088.000000000
259108187744969280.000000000
379723539627476544.000000000
43293950651076040.000000000
27591643934...

result:

ok Your answer is acceptable!^ ^

Extra Test:

score: 0
Extra Test Passed