Thursday, November 3, 2016

Lightoj 1305 - Area of a Parallelogram.



N:B Please don't copy source code.Try to find out the geometrical logic and work hard.

There are 2 or more solution of this problem. I have mentioned one by commenting by uses matrix formula for finding area of quadrilateral.

Or read again the problem.

 C program:

#include<stdio.h>
int main()
{

    double Ax,Ay,Bx,By,Cx,Cy,x,y;
    double a,b,c,ans,s,d,h;
    int i,test;
    scanf("%d",&test);
    for(i=1; i<=test; i++)
    {
        scanf("%lf %lf %lf %lf %lf %lf",&Ax,&Ay,&Bx,&By,&Cx,&Cy);
        x=Ax+Cx-Bx;
        y=Ay+Cy-By;
        a=sqrt((Ax-Bx)*(Ax-Bx)+(Ay-By)*(Ay-By));
        b=sqrt((x-Ax)*(x-Ax)+(y-Ay)*(y-Ay));
        c=sqrt((x-Bx)*(x-Bx)+(y-By)*(y-By));
        s=(a+b+c)/2.0;
        d = sqrt(s*(s-a)*(s-b)*(s-c));
       // ans = .5*fabs((Ax*By+Bx*Cy+Cx*y+x*Ay)-(Ax*y+x*Cy+Cx*By+Bx*Ay));/** Matrix solution **/

        printf("Case %d: %.0lf %.0lf %.0lf\n",i,x,y,2*d);
    }
    return 0;
}

No comments:

Post a Comment