poj 2954 pick定理

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
struct point{
	int x,y;
}p[1000];
int gcd(int a,int b)
{
    if(b==0) return a;
	return gcd(b,a%b);
}
int onedge(int n,point *p)//多边形边上的网格点数
{
	int i,ret=0;
	for(i=0;i<n;i++)
		ret+=gcd(abs(p[i].x-p[(i+1)%n].x),abs(p[i].y-p[(i+1)%n].y));
	return ret;
}
double getarea(point *p,int n)
{
	  int i;
	  double area=0;
      for(i=0;i<n;i++) area+=p[(i+1)%n].y*(p[i].x-p[(i+2)%n].x);
	  return area;
}
int inside(int n,point *p)
{
	double area=0;
    area=getarea(p,n);
	return (fabs(area)-onedge(n,p))/2+1;
}
int main()
{
	int t,cases=1,i;
	int n,dx,dy;
    while(1)
	{
		int flag;
        for(i=0;i<3;i++)
		{
			flag=0;
			scanf("%d%d",&dx,&dy);
			if(dx!=0||dy!=0)
				flag=1;
            p[i].x=dx;
			p[i].y=dy;
		}
		if(!flag) break;
	    int in;
		in=inside(3,p);
    	    printf("%d\n",in);
	
	}
	return 0;
}

posted @ 2011-10-18 12:36  Because Of You  Views(142)  Comments(0Edit  收藏  举报