知识点 1.s= 边上点的数量/2+内点数量-1;
2.边上点的求法 am = gcd(x1-x2,y1-y2);
3.面积求法 凸包或有凹点都用叉积公式,不能化成一个个三角形求。
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<ctime>
using namespace std;
int n,m,dx,dy,x[20000],y[20000],prex,prey;
int gcd(int x,int y)
{
int re;
while(y)
{
int t = y;
y = x%y;
x = t;
}
return x;
}
int toCalEdgePoints()
{
int result = 0;
for(int i=0;i<n;i++)
{
int ky = y[(i+1)%n]-y[i],kx = x[(i+1)%n]-x[i];
result+=gcd(abs(kx),abs(ky));
}
return result;
}
double toCalArea()
{
double result = 0.0;
for(int i=0;i<n;i++)
result+=y[(i+1)%n]*x[i]-x[(i+1)%n]*y[i];
return fabs(result/2.0);
}
int main()
{
int i1 = 1,t;
scanf("%d",&t);
while(t--)
{
prex = 0;
prey = 0;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d%d",&dx,&dy);
prex+=dx;
prey+=dy;
x[i] = prex;
y[i] = prey;
}
int edgePoints = toCalEdgePoints();
double area = toCalArea();
printf("Scenario #%d:\n",i1);
i1++;
printf("%d %d %.1f\n\n",(int)(area+1-(double)edgePoints/2+0.00001),edgePoints,area);
}
return 0;
}