QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#717039#9103. Zayin and FireballMu_SilkWA 1ms4284kbC++204.9kb2024-11-06 16:43:092024-11-06 16:43:09

Judging History

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

  • [2024-11-06 16:43:09]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4284kb
  • [2024-11-06 16:43:09]
  • 提交

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){
    if(sgn(a.r)==0||sgn(b.r)==0)return false;
    if(sgn(a.r-b.r)==0&&sgn(a.o.x-b.o.x)==0&&sgn(a.o.y-b.o.y)==0)return false;
    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);
            }
        }
    }
    // for(auto i:x)cout<<i<<" ";
    // cout<<"\n";
    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];
        // cout<<l<<" "<<r<<"\n";
        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&&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;
}

详细

Test #1:

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

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
28.274334
36.296045
28.274334
28.274334
28.157137
417.831823
97.568489
125660.564551
125660.564551
125660.564789
125660.564789
31412.784943
39.579337
301.976982
18751.965611
70.914255

result:

wrong answer 13th numbers differ - expected: '38.21885', found: '97.56849', error = '1.55289'