poj 2954(pick定理)

pick定理:一个计算点阵中顶点在格点上的多边形面积公式,该公式可以表示为2S=2a+b-2,其中a表示多边形内部的点数,b表示多边形边界上的点数,s表示多边形的面积。

一个蛮神奇的定理。。用来求内点。。边界点作差求gcd就可以了。。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,l,r) for(int i=l;i>=r;i--)
#define link(x) for(edge *j=h[x];j;j=j->next)
#define inf 1e9
#define eps 1e-8
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define succ(x) (1<<x)
#define lowbit(x) (x&(-x))
#define sqr(x) ((x)*(x))
#define NM 200005
#define pi 3.141592653
using namespace std;

int read(){
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f*x;
}


struct P{
	int x,y;
	P(int x=0,int y=0):x(x),y(y){}
	P operator-(const P&o){return P(x-o.x,y-o.y);}
	P operator+(const P&o){return P(x+o.x,y+o.y);}
	int operator*(const P&o){return x*o.x+y*o.y;}
	int operator%(const P&o){return x*o.y-y*o.x;}
}a,b,c,d;
int s,t;
int gcd(int x,int y){return y==0?x:gcd(y,x%y);}


int main(){
	while(1){
		a.x=read();a.y=read();b.x=read();b.y=read();c.x=read();c.y=read();
		if(!(a.x||b.x||c.x||a.y||b.y||c.y))break;
		t=0;s=0;
		if((b-c)*(a-c)==0)swap(a,c);
		else if((a-b)*(c-b)==0)swap(b,a);
		s=(b-a)%(c-a);
		s=abs(s);
		t=gcd(abs(b.y-a.y),abs(b.x-a.x))+gcd(abs(c.x-a.x),abs(c.y-a.y))+gcd(abs(b.x-c.x),abs(b.y-c.y));
		printf("%d\n",(s-t+2)/2);
	}
	return 0;
}

Triangle
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 6041 Accepted: 2596

Description

A lattice point is an ordered pair (x, y) where x and y are both integers. Given the coordinates of the vertices of a triangle (which happen to be lattice points), you are to count the number of lattice points which lie completely inside of the triangle (points on the edges or vertices of the triangle do not count).

Input

The input test file will contain multiple test cases. Each input test case consists of six integers x1, y1, x2, y2, x3, and y3, where (x1, y1), (x2, y2), and (x3, y3) are the coordinates of vertices of the triangle. All triangles in the input will be non-degenerate (will have positive area), and −15000 ≤ x1, y1, x2, y2, x3, y3 ≤ 15000. The end-of-file is marked by a test case with x1y1 = x2 = y2 = x3 = y3 = 0 and should not be processed.

Output

For each input case, the program should print the number of internal lattice points on a single line.

Sample Input

0 0 1 0 0 1
0 0 5 0 0 5
0 0 0 0 0 0

Sample Output

0
6

Source

[Submit]   [Go Back]   [Status]   [Discuss]


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值