1,。如果三角形PAB,PAC和PBC的面积之和与三角形ABC的面积相等,即可判定点P在三角形ABC内(包括在三条边上)。
#include"stdio.h"
#include"math.h"struct node
{
int x;
int y;
}no1[111],no2[1001];
double dist(int xa,int ya,int xb,int yb){
return(double)sqrt( (xa-xb)*(xa-xb)+(ya-yb)*(ya-yb) );
}
double area(node a,node b,node c) //知道三个点求三角形面积
{
double a1=dist(a.x,a.y,b.x,b.y);
double b1=dist(b.x,b.y,c.x,c.y);
double c1=dist(c.x,c.y,a.x,a.y);
double s=(a1+b1+c1)/2;
double t=(double)sqrt(s*(s-a1)*(s-b1)*(s-c1));
return t;
}
int main()
{
int n,m,i,j,k,l,num,count,tatle=1;
double sum,sum1,sum2,sum3;
while(scanf("%d %d",&n,&m)!=EOF)
{
count=0;
for(i=0;i<n;i++)
scanf("%d %d",&no1[i].x,&no1[i].y);
for(i=0;i<m;i++)
scanf("%d %d",&no2[i].x,&no2[i].y);
for(i=0;i<n-2;i++)
for(j=i+1;j<n-1;j++)
for(k=j+1;k<n;k++)
{
num=0;
sum=area(no1[i],no1[j],no1[k]);
for(l=0;l<m;l++)
{
sum1=area(no2[l],no1[j],no1[k]);
sum2=area(no1[i],no2[l],no1[k]);
sum3=area(no1[i],no1[j],no2[l]);
if(((int)sum1+(int)sum3+(int)sum2)==(int)sum)
num++;
}
if(num%2!=0)
count++;
}
printf("Case %d: %d\n",tatle++,count);
}
return 0;
}