#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
struct node
{
int x,y;
}a[110];
int gcd(int x,int y)
{
return y?gcd(y,x%y):x;
}
int getd(node x,node y)
{
if(x.x==y.x)
{
return max(x.y,y.y)-min(x.y,y.y)-1;
}
if(x.y==y.y)
{
return max(x.x,y.x)-min(x.x,y.x)-1;
}
if(x.x>y.x)
{
swap(x,y);
}
int a=y.y-x.y;
int b=x.x-y.x;
int d=gcd(abs(a),abs(b));
return d-1;
}
int gets(node x,node y)
{
int x1=x.x-a[1].x;
int y1=x.y-a[1].y;
int x2=y.x-a[1].x;
int y2=y.y-a[1].y;
return x1*y2-x2*y1;
}
int main()
{
int t;
cin>>t;
for(int j=1;j<=t;j++)
{
int n;
cin>>n;
int ans1=0,ans2=0;
for(int i=1;i<=n;i++)
{
cin>>a[i].x>>a[i].y;
if(i>1)
{
a[i].x=a[i-1].x+a[i].x;
a[i].y=a[i-1].y+a[i].y;
}
}
for(int i=2;i<=n;i++)
{
ans1+=getd(a[i],a[i-1]);
if(i<n)
ans2+=gets(a[i],a[i+1]);
}
ans1+=getd(a[1],a[n]);
double x=1.0*abs(ans2)*0.5;
ans1+=n;
int k=int(x)+1-ans1/2;
printf("Scenario #%d:\n%d %d %.1lf\n",j,k,ans1,x);
printf("\n");
}
return 0;
}
求整数端点线段内端点数+pick定理+叉积求多边形面积
最新推荐文章于 2024-08-22 17:47:37 发布