标签:
题目:http://poj.org/problem?id=1265
题意:
题目解析:
#include <iostream> #include <string.h> #include <stdio.h> #include <algorithm> #include <math.h> #include <queue> #define inf 0x3f3f3f3f #define eps 1e-9 typedef long long ll; using namespace std; struct point { int x,y; } q[1010]; int n; ll num,In; double S; int gcd(int A,int B) { return B==0?A:gcd(B,A%B); } int Mult(point A,point B) { return A.x*B.y-B.x*A.y; } int main() { int T,xx,yy,sx,sy,dx,dy,K=0; scanf("%d",&T); while(T--) { scanf("%d",&n); sx=sy=0; S=0; num=0; for(int i=1; i<=n; i++) { scanf("%d%d",&xx,&yy); sx+=xx; sy+=yy; q[i].x=sx; q[i].y=sy; } q[0].x=q[n].x; q[0].y=q[n].y; for(int i=0; i<n; i++) { S+=Mult(q[i],q[i+1]); dx=abs(q[i].x-q[i+1].x); dy=abs(q[i].y-q[i+1].y); num+=gcd(max(dx,dy),min(dx,dy)); } S=fabs(S/2);//不确定S是否为正数 In=int(S)+1-num/2; printf("Scenario #%d:\n",++K); printf("%I64d %I64d %.1f\n\n",In,num,S); } return 0; }
POJ1265:Area(多边形面积公式+pick公式) 好题
标签:
原文地址:http://www.cnblogs.com/zhangmingcheng/p/4275973.html