poj2954 Triangle

题目描述:

vjudge

POJ

题解:

$Pick$定理+叉积求三角形面积。

注意叉积是有向面积可能为负。

代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
struct Point
{
    ll x,y;
    Point(){}
    Point(ll x,ll y):x(x),y(y){}
    Point operator + (const Point&a)const{return Point(x+a.x,y+a.y);}
    Point operator - (const Point&a)const{return Point(x-a.x,y-a.y);}
    ll operator ^ (const Point&a)const{return x*a.y-y*a.x;}
};
typedef Point Vector;
Point a,b,c;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
ll abs_(ll x){return x>0?x:-x;}
int main()
{
    while(1)
    {
        scanf("%lld%lld%lld%lld%lld%lld",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y);
        if(!a.x&&!a.y&&!b.x&&!b.y&&!c.x&&!c.y)break;
        ll S_2 = abs_((b-a)^(c-a));
        ll B = gcd(abs_(a.x-b.x),abs_(a.y-b.y))
              +gcd(abs_(a.x-c.x),abs_(a.y-c.y))
              +gcd(abs_(b.x-c.x),abs_(b.y-c.y));
        ll A = (S_2-B+2)/2;
        printf("%lld\n",A);
    }
    return 0;
}
View Code

 

posted @ 2019-06-06 10:06  LiGuanlin  阅读(238)  评论(0编辑  收藏  举报