题意:求给定的多边形的内部点的个数,边上的点的个数。及面积
思路:多边形内的坐标点的个数:PICK公式:S=I+E/2-1 S,面积,I多边形的内坐标点的个数,E多边形的边上坐标点的个数。
线段的端点在坐标点上,其经过的坐标点的个数:GCD(dx,dy)+1;
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
using namespace std;
const double EPS = 1e-12;
const double INF = 1e20;
bool zero(double t){return -EPS<t&&t<EPS;}
struct cvector{
double x,y;
cvector(){}
cvector(double a,double b){x=a,y=b;}
};
cvector operator-(cvector a,cvector b){
return cvector(a.x-b.x,a.y-b.y);
}
cvector operator+(cvector a,cvector b){
return cvector(a.x+b.x,a.y+b.y);
}
cvector operator*(double k,cvector a){
return cvector(k*a.x,k*a.y);
}
double operator*(cvector a,cvector b){
return a.x*b.x+a.y*b.y;
}
double operator^(cvector a,cvector b){
return a.x*b.y-b.x*a.y;
}
double length(double t){return t<0?-t:t;}
double length(cvector t){return sqrt(t*t);}
struct cpoint{
int x,y;
void get(){scanf("%d%d",&x,&y);}
};
cvector operator-(cpoint a,cpoint b){
return cvector(a.x-b.x,a.y-b.y);
}
double dist(cpoint a,cpoint b){
return length(a-b);
}
int n;
cpoint re[109];
double x_mul(cpoint a,cpoint b,cpoint c){
return (a-c)^(b-c);
}
int gcd(int x,int y){
return x==0?y:gcd(y%x,x);
}
int main()
{
freopen("in.txt","r",stdin);
int cas,T = 1;
scanf("%d",&cas);
while(cas--)
{
if(T>1) printf("\n");
scanf("%d",&n);
re[0].get();
for(int i=1;i<n;i++)
re[i].get(),re[i].x+=re[i-1].x,re[i].y+=re[i-1].y;
re[n] = re[0];
double area = 0;
cpoint o;o.x=0,o.y=0;
for(int i=0;i<n;i++)
{
area += (x_mul(re[i],re[i+1],o)/2);
}
if(area<0) area = -area;
int a=0,b=0;
for(int i=0;i<n;i++)
{
int x = abs(re[i].x-re[i+1].x);
int y = abs(re[i].y-re[i+1].y);
a+= gcd(x,y);
}
b = area - a/2+1;
printf("Scenario #%d:\n",T++);
printf("%d %d %.1lf\n",b,a,area);
}
return 0;
}