poj 2954

裸的PICK定理。 在结束条件上卡了一下,原来是这么写的 :while( cin>>x1>>y1>>x2>>y2>>x3>>y3&&(x1+y1+x2+y2+x3+y3))   

                                               每个数不为0的条件应该是这样:  while( cin>>x1>>y1>>x2>>y2>>x3>>y3&&(x1||y1||x2||y2||x3||y3))


#include <queue>
#include <stack>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <limits.h>
#include <string.h>
#include <string>
#include <algorithm>
using namespace std;
struct point{ int x,y;};
point p[3];
int gcd(int n,int m)//斜率为整数时 ,退出循环。 有点没想明白。。 
{
	return m == 0 ? n : gcd(m,n%m);
}
int intp_insegment(point a, point b)
{
	int aa = abs(b.y - a.y), bb = abs(b.x - a.x);
	if(aa == 0 && bb == 0)	return 0;
	if(aa == 0)	return bb - 1;
	if(bb == 0)	return aa - 1;
	return gcd(aa, bb) - 1;
}
long long intp_edge(point p[],int n)
{
	long long ans = n;
	for(int i=0; i<n; i++)
		ans += intp_insegment(p[i], p[(i+1)%n]);
	return ans;
}
double area_polygon(point p[],int n)
{
	double s = 0.0;
	for(int i=0; i<n; i++)
		s += p[(i+1)%n].y *1ll* p[i].x - p[(i+1)%n].x*1ll * p[i].y;
	return fabs(s)/2.0;
} 
long long intp_inpolygon(point p[],int n)
{
	double area = area_polygon(p,3);
	long long pinedge = intp_edge(p,3);
	return (long long)(area) - pinedge/2ll + 1;
}
int main()
{
	int x1,y1,x2,y2,x3,y3;
	
	while( cin>>x1>>y1>>x2>>y2>>x3>>y3&&(x1||y1||x2||y2||x3||y3))
	{
                p[0].x=x1;
                p[0].y=y1;
                p[1].x=x2;
                p[1].y=y2;
                p[2].x=x3;
                p[2].y=y3;
		long long ans = intp_inpolygon(p,3);
		printf("%lld\n",ans);
	}
return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值