Wednesday, 27 January 2016

UVa 11437 - Triangle Fun

//\\__ hr1212 __//\\

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mi;

#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%lld\n",a)
#define nl printf("\n");
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define f(i,a,b) for(i=a;i<b;i++)
#define rf(i,a,b) for(i=a;i>=b;i--)
#define clr(x,a) memset(x,a,sizeof(x))
#define MAX 1000100
#define MOD 1000000007

int n,m;

int main(){
    int r,k,i,c=0,x=0,y=0,j,t,l,z,x1=0,y1=0;
    ll ans=0;string p;

    double ax,ay,bx,by,cx,cy,dx,dy,ex,ey,fx,fy,px,py,qx,qy,rx,ry,mad,cad,mbe,cbe,mcf,ccf,lpr,lqr,lpq,s,area;

    si(t);
    while(t--){
        cin>>ax>>ay>>bx>>by>>cx>>cy;
        dx=(cx+2*bx)/3;dy=(cy+2*by)/3;
        ex=(ax+2*cx)/3;ey=(ay+2*cy)/3;
        fx=(bx+2*ax)/3;fy=(by+2*ay)/3;

        mad=(ay-dy)/(ax-dx);cad=ay-mad*ax;
        mbe=(by-ey)/(bx-ex);cbe=by-mbe*bx;
        mcf=(cy-fy)/(cx-fx);ccf=cy-mcf*cx;

        px=(cbe-cad)/(mad-mbe);py=(mad*cbe-mbe*cad)/(mad-mbe);
        qx=(cbe-ccf)/(mcf-mbe);qy=(mcf*cbe-mbe*ccf)/(mcf-mbe);
        rx=(ccf-cad)/(mad-mcf);ry=(mad*ccf-mcf*cad)/(mad-mcf);

        lpr=sqrt((px-rx)*(px-rx)+(py-ry)*(py-ry));
        lqr=sqrt((qx-rx)*(qx-rx)+(qy-ry)*(qy-ry));
        lpq=sqrt((px-qx)*(px-qx)+(py-qy)*(py-qy));

        s=(lpr+lqr+lpq)/2;

        area=sqrt(s*(s-lpr)*(s-lqr)*(s-lpq));

        ans=(area+0.5);
        pi(ans);
    }

    return 0;
}

No comments:

Post a Comment