0
题目
1
分析:
皮克定理:
内部的点的个数 + 边上的点的个数/2 + 1 = 该多边形面积
利用向量叉乘求面积,利用最大公约数求一条边上的点的个数,结合皮克定理,求出内部点的个数。
2
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <cmath>
///int a,int b; (double)(a/b)得到的是int,((double)a)/b 与 a/(double)(b)这两个才都可以得到double
///abs是取绝对值(头文件<cmath>),fabs(头文件<math.h>)是浮点数取绝对值
using namespace std;
struct points{
int x;
int y;
}point_last,point_cur,point_ini,point_cal;
int n;
int ins;//inside
int edg;//edge
double area;
int gcd(int a,int b){//最大公约数
return b?gcd(b,a%b):a;
}
void Area(struct points p0,struct points p1,struct points p2){
area+=( (p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x) );
//cout<<p1.x<<" "<<p1.y<<" "<<p2.x<<" "<<p2.y<<" "<<area<<endl;
}
int main(){
int kase;
scanf("%d",&kase);
for(int kk=1;kk<=kase;kk++){
///ini + e + area
ins=0;edg=0;area=0;
scanf("%d",&n);
point_ini.x=point_last.x=0;point_ini.y=point_last.y=0;
point_cal.x=0;point_cal.y=0;
for(int i=1;i<=n;i++){
int a,b;
scanf("%d%d",&a,&b);
point_cur.x=point_last.x+a;point_cur.y=point_last.y+b;
edg+=gcd(abs(a),abs(b));
if(i>1&&i<n){
Area(point_cal,point_last,point_cur);
}
point_last=point_cur;
}
area/=2; area=fabs(area);
ins=(int)(area+1-(double)edg/2);
printf("Scenario #%d:\n%d %d %.1f\n\n",kk,ins,edg,area);
}
}