QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#504964#9103. Zayin and FireballAfterlife#TL 19ms3864kbC++203.4kb2024-08-04 17:55:422024-08-04 17:55:42

Judging History

你现在查看的是测评时间为 2024-08-04 17:55:42 的历史记录

  • [2024-09-23 15:03:56]
  • 管理员手动重测本题所有提交记录
  • 测评结果:TL
  • 用时:19ms
  • 内存:3828kb
  • [2024-08-04 17:55:42]
  • 评测
  • 测评结果:0
  • 用时:19ms
  • 内存:3864kb
  • [2024-08-04 17:55:42]
  • 提交

answer

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

const int N=5e2+1e1+7;

const double eps=1e-6;

struct P {
    double x,y;
    P operator -(const P &s) const
    {
        return {x-s.x,y-s.y};
    }
    P operator +(const P &s) const
    {
        return {x+s.x,y+s.y};
    }

    double Len() const
    {
        return hypot(x,y);
    }

    double Len2() const
    {
        return x*x+y*y;
    }

    P Len(const double d) const 
    {
        return {x*d,y*d};
    }

    P operator *(const double d) const
    {
        return {x*d,y*d};
    }

    P operator /(const double d) const
    {
        return {x/d,y/d};
    }

    P unit() const 
    {
        return *this/Len();
    }

    P symmetry(const P &b) const
    {
        return b+b-*this;
    }
};

bool operator <(const P &a,const P &b)
{
    return a.y<b.y;
}

double dot(const P &a,const P &b)
{
    return a.x*b.x+a.y*b.y;
}

struct C {
    P o;
    double r;
    void rd()
    {
        int a,b,c;
        cin>>a>>b>>c;
        o.x=a,o.y=b,r=c;
    }
};

double sgn(double x)
{
    return x<-eps?-1:x>eps;
}

vector<P> circle_line_inter(P o,double r,P a,P b)
{
    P h=a+(b-a).unit()*dot(o-a,(b-a).unit());
    double t=r*r-(h-o).Len2();
    if(sgn(t)<0)
        return {};
    else if(!sgn(t))
        return {h,h};
    else
    {
        P p1=(a-b).Len(sqrt(t))+h;
        P p2=p1.symmetry(h);
        return {p1,p2};
    }
}

vector<pair<C,C> >cs;

double eval(double X)
{
    map<P,int>D;
    P u={X,1},v={X,0};
    for(auto [c,d]:cs)
    {
        auto pts=circle_line_inter(c.o,c.r,u,v);
        if(!pts.size())
            continue;
        auto a=pts[0],b=pts[1];
        if(b<a)
            swap(a,b);
        D[a]++;
        D[b]--;
        pts=circle_line_inter(d.o,d.r,u,v);
        if(pts.size())
        {
            auto e=pts[0],f=pts[1];
            if(f<e)
                swap(e,f);
            a.y=max(a.y,e.y);
            b.y=min(b.y,f.y);
            if(a.y<=b.y)
                D[a]--,D[b]++;
        }
    }
    if(!D.size())
        return 0;
    double ret=0;
    int S=0;
    for(auto it=D.begin();next(it)!=D.end();it++)
    {
        double dy=next(it)->first.y-it->first.y;
        S+=it->second;
        if(S>0)
        {
            ret+=dy;
        }
    }
    return ret;
}

double sim(double l,double r)
{
    return (eval(l)+eval(r)+4*eval((l+r)/2))*(r-l)/6;
}

double simp(double l,double r)
{
    // if(r-l<0.001)
    //     return 0;
    double mid=(l+r)/2;
    if(fabs(sim(l,r)-sim(l,mid)-sim(mid,r))<0.00001)
        return sim(l,mid)+sim(mid,r);
    return simp(l,mid)+simp(mid,r);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;
    cin>>T;
    while(T--)
    {
        int n;
        cin>>n;
        cs.clear();
        cs.resize(n);
        double mnX=1e18,mxX=0;
        for(auto &[c,d]:cs)
        {
            c.rd(),d.rd();
            mnX=min(mnX,c.o.x-c.r);
            mnX=min(mnX,d.o.x-d.r);
            mxX=max(mxX,c.o.x+c.r);
            mxX=max(mxX,d.o.x+d.r);
        }
        double LEN=mxX-mnX;
        double ans=0;
        for(int i=0;i<100;i++)
        {
            double L=mnX+LEN*i/100,R=L+LEN/100;
            ans+=simp(L,R);
        }
        cout<<fixed<<setprecision(9)<<ans<<"\n";
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 19ms
memory: 3864kb

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.000000000
9.424774785
9.424772071
11.163306528
3.957933714
18.849541148
28.274324214
36.296001787
28.274324214
28.274324214
28.157138788
417.831826785
38.218869149
125660.564523860
125660.564523860
125660.564759827
125660.564759827
31412.784927277
39.579331978
301.267432982
18751.965583975
70.9142...

result:

wrong answer 19th numbers differ - expected: '78.31730', found: '39.57933', error = '0.49463'