Editorial for Bedao Grand Contest 05 - STOLEN


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Code mẫu

#include <bits/stdc++.h>
#define ld long double
using namespace std;
ld dttamgiac(ld xa, ld xb, ld xc, ld ya, ld yb, ld yc){
    return (0.50000*abs((xb-xa)*(yc-ya)-(xc-xa)*(yb-ya)));
}
ld res,a[5],b[5],c[5],d[5];
ld mu4(ld x){
    return x*x*x*x;
}
ld mu3(ld x){
    return x*x*x;
}
ld mu2(ld x){
    return x*x;
}
ld ptbac1(ld _a, ld _b){
    return -_b/_a;
}
ld ptbac2(ld _a, ld _b,ld _c){
    return -_b/(2.0000*_a);
}
ld ptbac3(ld _a, ld _b, ld _c, ld _d){
    ld delta=_b*_b-3.0000*_a*_c;
    ld ans=0;
    if(delta==0){
        ans=(-_b+cbrt(mu3(_b)-27.000*mu2(_a)*_d))/(3.0000*_a);
        return ans;
    }
    ld k=(9.0000*_a*_b*_c-2.0000*_b*_b*_b-27.0000*_a*_a*_d)/(2.000*sqrt(mu3(abs(delta))));
    if( delta>0 && abs(k)>1)
        ans=(sqrt(delta)*abs(k)/(3.0000*_a*k))*(cbrt(abs(k)+sqrt(mu2(k)-1))+cbrt(abs(k)-sqrt(mu2(k)-1)))-_b/(3.0000*_a);
    if(delta<0)
        ans=(sqrt(abs(delta))/(3.0000*_a))*(cbrt(k+sqrt(mu2(k)+1))+cbrt(k-sqrt(mu2(k)+1)))-_b/(3.0000*_a);
    return ans;
}
ld giao(int tt1,int tt2){
    int _a=a[tt1]-a[tt2], _b=b[tt1]-b[tt2] , _c=c[tt1]-c[tt2], _d=d[tt1]-d[tt2];
    if(_a==0&&_b==0)
        return ptbac1(_c,_d);
    if(_a==0)
        return ptbac2(_b,_c,_d);
    return ptbac3(_a,_b,_c,_d);
}
ld cal(ld x, int tt1, int tt2){
    return (((a[tt1]-a[tt2])/4.0000)*mu4(x)+((b[tt1]-b[tt2])/3.000)*mu3(x)+((c[tt1]-c[tt2])/2.000)*mu2(x)+(d[tt1]-d[tt2])*x);
}
ld tichphan(ld _x, ld _y, int tt1, int tt2){
    return (cal(_y,tt1,tt2)-cal(_x,tt1,tt2));
}
int main()
{
    freopen("STOLEN.INP","r",stdin);
    freopen("STOLEN.OUT","w",stdout);
    for(int i=1;i<=3;i++){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
        if(i!=1&&a[i]==0&&b[i]==0){
            swap(a[i],a[1]); swap(b[i],b[1]); swap(c[i],c[1]); swap(d[i],d[1]);
        }
    }
    ld x1,x2,x3;
    x1=giao(1,2);  x2=giao(2,3);  x3=giao(1,3);
    if(a[1]==0&&a[2]==0&&a[3]==0&&b[1]==0&&b[2]==0&&b[3]==0){
        ld Y1=a[1]*mu3(x1)+b[1]*mu2(x1)+c[1]*x1+d[1];
        ld Y2=a[2]*mu3(x2)+b[2]*mu2(x2)+c[2]*x2+d[2];
        ld Y3=a[3]*mu3(x3)+b[3]*mu2(x3)+c[3]*x3+d[3];
        cout<<setprecision(6)<<fixed<<dttamgiac(x1,x2,x3,Y1,Y2,Y3);
        return 0;
    }
    if(x1>x3){
        swap(x1,x3);
        swap(a[2],a[3]); swap(b[2],b[3]); swap(c[2],c[3]); swap(d[2],d[3]);
    }
    ld xx1=a[1]*mu3(x2)+b[1]*mu2(x2)+c[1]*x2+d[1];
    ld xx2=a[2]*mu3(x2)+b[2]*mu2(x2)+c[2]*x2+d[2];
    if(xx1>xx2){
        if(x1<x2&&x2<x3)
            res=tichphan(x1,x2,1,2)+tichphan(x2,x3,1,3);
        else{
            if(x2<x1)
                res=tichphan(x2,x3,1,3)-tichphan(x2,x1,1,2);
            else
                res=tichphan(x1,x2,1,2)-tichphan(x3,x2,1,3);
        }
    }
    else{
        if(x1<x2&&x2<x3)
            res=tichphan(x1,x2,2,1)+tichphan(x2,x3,3,1);
        else{
            if(x2<x1)
                res=tichphan(x2,x3,3,1)-tichphan(x2,x1,2,1);
            else
                res=tichphan(x1,x2,2,1)-tichphan(x3,x2,3,1);
        }
    }
    cout<<setprecision(6)<<fixed<<res;
}

Comments

Please read the guidelines before commenting.


There are no comments at the moment.