QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#715084#8082. Minimum Euclidean Distanceqzez#TL 90ms3932kbC++141.7kb2024-11-06 10:21:492024-11-06 10:21:49

Judging History

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

  • [2024-11-06 10:21:49]
  • 评测
  • 测评结果:TL
  • 用时:90ms
  • 内存:3932kb
  • [2024-11-06 10:21:49]
  • 提交

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=12){
    double mid=(l+r)/2,fl=calc(l,mid),fr=calc(mid,r);
    if(abs(fl+fr-ans)<eps*15&&d<0)return fl+fr+(fl+fr-ans)/15;
    return solve(l,mid,eps/2,fl,d-1)+solve(mid,r,eps/2,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);
        r=sqrt(dis2(s-t))/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: 1ms
memory: 3932kb

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.250000000
0.750000000
1.875000000

result:

ok Your answer is acceptable!^ ^

Test #2:

score: 0
Accepted
time: 90ms
memory: 3896kb

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.500000000
51.470588235
1051.250000000
66.625000000
174.125000000
562.675000000
272.394230769
287.385000000
689.625000000
436.250000000

result:

ok Your answer is acceptable!^ ^

Test #3:

score: -100
Time Limit Exceeded

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:


result: