QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#716911#9103. Zayin and FireballMu_SilkWA 1ms4228kbC++204.7kb2024-11-06 16:20:252024-11-06 16:20:25

Judging History

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

  • [2024-11-06 16:20:25]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4228kb
  • [2024-11-06 16:20:25]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

double eps=1e-8;
int sgn(double x){
    if(x>eps)return 1;
    if(x<-eps)return -1;
    return 0;
}

struct vec{
    double x,y;
    vec operator-(vec a){return {x-a.x,y-a.y};}
    vec operator+(vec a){return {x+a.x,y+a.y};}
    double operator*(vec a){return x*a.x+y*a.y;}
    vec operator*(double a){return {x*a,y*a};}
    vec operator/(double a){return {x/a,y/a};}
    double len(){return hypot(x,y);}
    double len2(){return x*x+y*y;}
    vec rot90(){return {-y,x};}
    vec trunc(double l){return (*this)*l/len();}
};

double cross(vec a,vec b){
    return a.x*b.y-a.y*b.x;
}

struct seg{
    vec a,b;
};

struct cir{
    vec o;
    double r;
};

struct func{
    double x0,y0,r;
    int sgn;
    int id;
    double v(double x){
        return y0+sgn*sqrt(r*r-(x-x0)*(x-x0));
    }
    double s(double l0,double r0){
        vec vl{l0,v(l0)},vr{r0,v(r0)};
        vec dl=vl-vec{x0,y0};
        vec dr=vr-vec{x0,y0};
        double a=acos((dl*dr)/(r*r));

        double s=r*r*a/2-fabs(cross(dl,dr))/2;
        double res=(v(l0)+v(r0))*(r0-l0)/2;
        return res+sgn*s;
    }
};

bool circle_circle_intersection(cir a,cir b,seg& s){
    double d=(a.o-b.o).len();
    if(d>a.r+b.r||d<fabs(a.r-b.r))return false;
    double l=((a.o-b.o).len2()+a.r*a.r-b.r*b.r)/(2*d);
    double h=sqrt(a.r*a.r-l*l);
    vec vl=(b.o-a.o).trunc(l),vh=vl.rot90().trunc(h);
    s=seg{a.o+vl+vh,a.o+vl-vh};
    return true;
}

void solve(){
    int n;cin>>n;
    vector<cir> c1(n),c2(n);
    for(int i=0;i<n;i++){
        cin>>c1[i].o.x>>c1[i].o.y>>c1[i].r;
        cin>>c2[i].o.x>>c2[i].o.y>>c2[i].r;
        c1[i].o.y+=2000;
        c2[i].o.y+=2000;
    }
    vector<double> x;
    for(int i=0;i<n;i++){
        x.push_back(c1[i].o.x-c1[i].r);
        x.push_back(c1[i].o.x+c1[i].r);
        x.push_back(c2[i].o.x-c2[i].r);
        x.push_back(c2[i].o.x+c2[i].r);
        seg s;
        if(circle_circle_intersection(c1[i],c2[i],s)){
            x.push_back(s.a.x);
            x.push_back(s.b.x);
        }
        for(int j=i+1;j<n;j++){
            seg s;
            if(circle_circle_intersection(c1[i],c1[j],s)){
                x.push_back(s.a.x);
                x.push_back(s.b.x);
            }
            if(circle_circle_intersection(c2[i],c2[j],s)){
                x.push_back(s.a.x);
                x.push_back(s.b.x);
            }
            if(circle_circle_intersection(c1[i],c2[j],s)){
                x.push_back(s.a.x);
                x.push_back(s.b.x);
            }
            if(circle_circle_intersection(c2[i],c1[j],s)){
                x.push_back(s.a.x);
                x.push_back(s.b.x);
            }
        }
    }
    sort(x.begin(),x.end());
    double ans=0;
    for(int i=0;i+1<x.size();i++){
        if(sgn(x[i]-x[i+1])==0)continue;
        double l=x[i],r=x[i+1];
        double m=(l+r)/2;
        vector<func> f;
        for(int j=0;j<n;j++){
            if(sgn(l-(c1[j].o.x-c1[j].r))>=0&&sgn(r-(c1[j].o.x+c1[j].r))<=0);
            else continue;

            func l1{c1[j].o.x,c1[j].o.y,c1[j].r,-1,1};
            func r1{c1[j].o.x,c1[j].o.y,c1[j].r, 1,-1};

            if(sgn(l-(c2[j].o.x-c2[j].r))>=0&&sgn(r-(c2[j].o.x+c2[j].r))<=0){
                func l2{c2[j].o.x,c2[j].o.y,c2[j].r,-1,-1};
                func r2{c2[j].o.x,c2[j].o.y,c2[j].r, 1,1};

                if(sgn(r2.v(m)-l1.v(m))<=0||sgn(r1.v(m)<=l2.v(m))){
                    f.push_back(l1);
                    f.push_back(r1);
                }
                else{
                    if(sgn(l1.v(m)-l2.v(m))<=0&&sgn(l2.v(m)<=r1.v(m))){
                        f.push_back(l1);
                        f.push_back(l2);
                    }
                    if(sgn(l1.v(m)-r2.v(m))<=0&&sgn(r2.v(m)<=r1.v(m))){
                        f.push_back(r2);
                        f.push_back(r1);
                    }
                }
            }
            else{
                f.push_back(l1);
                f.push_back(r1);
            }
        }
        sort(f.begin(),f.end(),[&](func a,func b){return a.v(m)<b.v(m);});
        // cout<<x[i]<<" "<<x[i+1]<<"\n";
        // cout<<f.size()<<"\n";
        int cnt=0;
        for(int i=0;i+1<f.size();i++){
            if(f[i].id>0)cnt++;
            else cnt--;
            if(cnt>0){
                ans+=f[i+1].s(l,r)-f[i].s(l,r);
            }
        }
        // cout<<l<<" "<<r<<" "<<f.size()<<" "<<ans<<"\n";
    }
    cout<<fixed<<setprecision(6)<<ans<<"\n";
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n=1;
    cin>>n;
    while(n--)solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 4228kb

input:

22
1
0 0 1 0 0 1
1
0 0 2 0 0 1
1
0 0 2 1 0 1
1
0 0 2 2 0 1
1
0 0 2 1 0 2
2
0 0 1 0 0 0
0 0 3 0 0 2
2
0 0 1 0 0 0
0 0 3 0 0 1
2
-233 0 3 -234 0 1
233 0 2 231 0 1
2
0 0 1 0 0 0
1 0 3 0 0 1
2
0 0 1 0 0 0
0 2 3 0 0 1
2
2 4 2 2 4 1
3 3 3 3 3 1
4
0 1 1 0 2 2
3 3 3 3 4 2
250 2 4 0 0 100
255 7 12 254 10 4
3...

output:

0.000000
9.424778
9.424778
11.163304
3.957934
18.849556
40.048253
36.296045
39.314019
40.048253
28.157137
417.831823
97.568489
125660.564551
125660.564551
125660.564789
125660.564789
62600.653364
61.216485
320.385645
18213.634923
70.914255

result:

wrong answer 7th numbers differ - expected: '28.27433', found: '40.04825', error = '0.41642'