View Code of Problem 2595

#include <stdio.h>
#include "string.h"
#include "math.h"
double lenth(double x1,double y1,double x2, double y2)
{return sqrt((x1-x2)*(x1-x2) +(y1-y2)*(y1-y2));}
double sfun(double x1,double y1,double x2,double y2,double x3,double y3)
{
    double a,b,c,p;
    a=lenth(x1,y1,x2,y2);
    b=lenth(x1,y1,x3,y3);
    c=lenth(x2,y2,x3,y3);
    p=(a+b+c)/2;
    return sqrt(p*(p-a)*(p-b)*(p-c));
}
int main(void)
{
    int m;
    scanf("%d",&m);
    while(m--)
    {
        int n,ans=0;
        double ss[101][2],label[4][2],s1,s2,s3,s4;
        double a,b,s=0;
        double sum=0;
        scanf("%d",&n);
        for(int i=0;i<n;i++)
            scanf("%lf%lf",&ss[i][0],&ss[i][1]);
        for(int i=0;i<4;i++)
            scanf("%lf%lf",&label[i][0],&label[i][1]);
        a=lenth(label[0][0],label[0][1],label[1][0],label[1][1]);
        b=lenth(label[1][0],label[1][1],label[2][0],label[2][1]);
        s=a*b;
        for(int i=0;i<n;i++)
        {
            sum=0;
            sum+=sfun(ss[i][0],ss[i][1],label[0][0],label[0][1],label[1][0],label[1][1]);
            sum+=sfun(ss[i][0],ss[i][1],label[1][0],label[1][1],label[2][0],label[2][1]);
            sum+=sfun(ss[i][0],ss[i][1],label[2][0],label[2][1],label[3][0],label[3][1]);
            sum+=sfun(ss[i][0],ss[i][1],label[3][0],label[3][1],label[0][0],label[0][1]);
            if((float)sum==s) ans++;
        }
        printf("%d\n",ans);
    }
}

Double click to view unformatted code.


Back to problem 2595