POJ 2954-Triangle(计算几何+皮克定理)

职务地址:POJ 2954

意甲冠军:三个顶点的三角形,给出,内部需求格点数。

思考:就像POJ 1265。

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <map>
using namespace std;
typedef long long LL;
const int inf=0x3f3f3f3f;
const double pi= acos(-1.0);
const double esp=1e-6;
int gcd(int a,int b)
{
    while(b){
        int r=b;
        b=a%b;
        a=r;
    }
    return a;
}
int main()
{
    int x1,y1,x2,y2,x3,y3;
    double S;
    int in,on;
    while(~scanf("%d %d %d %d %d %d",&x1,&y1,&x2,&y2,&x3,&y3)){
        in=on=S=0;
        if(!x1&&!y1&&!x2&&!y2&&!x3&&!y3) break;
        S=(x2-x1)*(y3-y1)-(x3-x1)*(y2-y1);
        if(S<0)
            S=-S;
        on=gcd(abs(x2-x1),abs(y2-y1))+gcd(abs(x1-x3),abs(y1-y3))+gcd(abs(x3-x2),abs(y3-y2));
        in=(S+2-on)/2;
        printf("%d
",in);
    }
    return 0;
}


版权声明:本文博主原创文章。博客,未经同意不得转载。

原文地址:https://www.cnblogs.com/gcczhongduan/p/4803228.html