Pick定理是说,在一个平面直角坐标系内,如果一个多边形的顶点全都在格点上,那么这个图形的面积恰好就等于边界上经过的格点数的一半加上内部所含格点数再减一。
题意不好懂,给出的x,y并不是坐标而是向x轴方向y轴方向移动的距离。
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 110
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
struct Point
{
double x,y;
Point(double x=,double y=):x(x),y(y) {}
}p[N];
typedef Point pointt;
pointt operator + (Point a,Point b)
{
return Point(a.x+b.x,a.y+b.y);
}
pointt operator - (Point a,Point b)
{
return Point(a.x-b.x,a.y-b.y);
}
int dcmp(double x)
{
if(fabs(x)<eps) return ;
else return x<?-:;
}
double cross(Point a,Point b)
{
return a.x*b.y-a.y*b.x;
}
double Polyarea(int n)
{
double area = ;
for(int i = ; i < n- ; i++)
area+=cross(p[i]-p[],p[i+]-p[]);
return area/;
}
int main()
{
int t,i,n,kk=;
cin>>t;
while(t--)
{
scanf("%d",&n);
int num = ;
p[].x = ,p[].y = ;
for(i = ; i <= n ;i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
p[i].x+=p[i-].x;
p[i].y+=p[i-].y;
}
p[n+] = ;
for(i = ; i <= n ;i++)
{
Point pp = p[i]-p[i+];
pp.x = fabs(pp.x),pp.y = fabs(pp.y);
if(dcmp(pp.x)==||dcmp(pp.y)==)
num+=pp.x+pp.y;
else
num+=__gcd((int)pp.x,(int)pp.y);
}
double s = Polyarea(n);
printf("Scenario #%d:\n",++kk);
printf("%d %d %.1f\n",(int)s+-num/,num,s);
puts("");
}
return ;
}