poj1265 Area

题目描述:

vjudge

POJ

由于题目乱码概括一下题意:

给出一个路径,求围成多边形中内部点数、边上点数(包括顶点)以及面积。

题解:

边上点数=$sum gcd(dx,dy)$

$Pick$定理:设$a$表示内部点数,$b$表示边上点数(包括顶点),$S$表示面积。则$$S=a+ frac{ b }{ 2 } -1$$

代码:

#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 150;
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;
int T,n;
Point p[N];
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
void work(int Sce)
{
    scanf("%d",&n);
    ll S = 0,b = 0;
    Point s0(0,0),s1(0,0),s2(0,0);
    Vector v;
    for(int i=1;i<=n;i++)
    {
        scanf("%I64d%I64d",&v.x,&v.y);
        ll x = v.x,y = v.y;
        if(x<0)x=-x;
        if(y<0)y=-y;
        b += gcd(x,y);
        s1 = s2,s2 = s2 + v;
        S += ((s1-s0)^(s2-s0));
    }
    if(S<0)S=-S;
    ll a = (S+2-b)/2;
    printf("Scenario #%d:
",Sce);
    printf("%I64d %I64d ",a,b);
    if(S&1)printf("%I64d.5

",S/2);
    else printf("%I64d.0

",S/2);
}
int main()
{
    scanf("%d",&T);
    for(int i=1;i<=T;i++)work(i);
    return 0;
}
View Code
原文地址:https://www.cnblogs.com/LiGuanlin1124/p/10983300.html