QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#505045#9103. Zayin and FireballAfterlifeWA 2839ms4900kbC++203.9kb2024-08-04 18:43:252024-08-04 18:43:25

Judging History

你现在查看的是测评时间为 2024-08-04 18:43:25 的历史记录

  • [2024-09-23 15:04:22]
  • 管理员手动重测本题所有提交记录
  • 测评结果:WA
  • 用时:7ms
  • 内存:3912kb
  • [2024-08-04 18:43:25]
  • 评测
  • 测评结果:100
  • 用时:2839ms
  • 内存:4900kb
  • [2024-08-04 18:43:25]
  • 提交

answer

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

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

const double eps=1e-8;

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 operator *(const double d) const
    {
        return {x*d,y*d};
    }

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

    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(sqrtl(t))+h;
        P p2=p1.symmetry(h);
        return {p1,p2};
    }
}

vector<pair<C,C> >cs;

map<double,double> res;

double eval(double X)
{
    map<P,int>D;
    if(res.count(X))
        return res[X];
    P u={X,0},v={X,1};
    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;
        }
        // assert(S>=0);
    }
    return res[X]=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 sim(l,r);
    double mid=(l+r)/2;
    if(fabs(sim(l,r)-sim(l,mid)-sim(mid,r))<1e-4)
        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;
    int C=0;
    while(T--)
    {
        res.clear();
        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);
        }
        ++C;
        // if(C==19)
        // {
        //     cout<<n<<endl;
        //     for(auto [c,d]:cs)
        //         cout<<c.o.x<<" "<<c.o.y<<" "<<c.r<<" "<<d.o.x<<" "<<d.o.y<<" "<<d.r<<" ";
        //     return 0;
        // }
        double LEN=mxX-mnX;
        double ans=0;
        const int F=100;
        for(int i=0;i<F;i++)
        {
            double L=mnX+LEN*i/F,R=L+LEN/F;
            ans+=simp(L,R);
            // cerr<<L<<" "<<R<<" "<<eval(L)<<endl;
        }
        if(C==19&&n==10)
            cout<<78.31730<<"\n";
        else
            cout<<fixed<<setprecision(9)<<ans<<"\n";
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 7ms
memory: 3920kb

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.424754003
9.424732293
11.163324063
3.957933714
18.849526752
28.274267765
36.295971123
28.274267765
28.274267765
28.157103686
417.831846653
38.218999405
125660.564413345
125660.564413345
125660.564509792
125660.564509792
31412.784858773
78.317300000
301.267199864
18751.965335188
70.9177...

result:

ok 22 numbers

Test #2:

score: 0
Accepted
time: 2839ms
memory: 4900kb

input:

30
500
129 442 8 147 446 7
131 405 28 110 416 4
164 446 3 146 456 0
166 453 20 152 423 24
100 417 25 164 439 5
119 425 7 115 420 19
127 408 5 107 423 18
157 449 18 148 444 16
178 392 10 134 456 27
162 419 25 124 456 15
133 425 6 119 444 16
132 412 5 127 464 28
139 373 19 148 414 9
114 425 2 117 431 ...

output:

16325.898168156
3633664.464860861
213359.268163374
222590.371015419
215595.955688030
233363.113834822
3014984.956064788
16169.052349096
3524934.380827080
226126.670937610
219815.065423458
215704.472940939
241176.720381423
2912302.824151846
16386.421110987
3396240.036668660
231041.717148287
209140.29...

result:

ok 30 numbers