POJ 2954 || Triangle ( pick定理

给你三角形三个顶点的坐标,

让你求三角形内部的点数

pick定理 三角形的面积 = 三条边上的点数/2 + 内部的点数  - 1

一个pick定理模板,边上的点用GCD算。

三角形面积叉积的一半。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
struct pnode
{
    int x,y;
    pnode(int xx=0,int yy=0):x(xx),y(yy){}
    pnode operator - (const pnode &b)const{
        return pnode(x-b.x,y-b.y);
    }
    int operator ^(const pnode &b)const{
        return x*b.y-y*b.x;
    }
    int pscanf(){
        return scanf("%d %d",&x,&y);
    }
    bool check(){
        if( x==0 && y==0)
            return true;
        return false;
    }
}a,b,c;
int Gcd( int a , int b )
{
   return  b==0 ? a : Gcd( b , a%b );
}
int Area( pnode p0 ,pnode p1, pnode p2 )
{
   return abs( (p1-p0)^(p2-p0) ) / 2 ;
}
int Edge( pnode a ,pnode b, pnode c )
{
   int E  = 0;
   E += Gcd( abs(a.x - b.x) , abs( a.y - b.y ) );
   E += Gcd( abs(a.x - c.x) , abs( a.y - c.y ) );
   E += Gcd( abs(b.x - c.x) , abs( b.y - c.y ) );
   return E;
}
int main(  )
{
    while( a.pscanf() && b.pscanf() && c.pscanf() )
    {
       if( a.check() && b.check() && c.check() )break;
       int area = Area( a , b ,c );
       int edge = Edge( a , b ,c );
       printf( "%d\n",area + 1 - edge/2);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值