
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1115#
大意:给你个n,有n个点,然后给你n个点的坐标,求这n个点形成的多边形的重心的坐标。
直接套模板,我也不知道什么意思。注意在POJ上面定义double时,输出f,如果输出lf则WA,HDU上面输出lf能A。
#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;
int n;
struct Point
{
double x,y;
} q[];
double cross(Point a,Point b)
{
return a.x*b.y-a.y*b.x;
}
Point interity(Point p[],int n)
{
Point inter= {,};
double area=;
for(int i=; i<n; i++)
{
double tmp=cross(p[i],p[(i+)%n]);
inter.x+=tmp*(p[i].x+p[(i+)%n].x);
inter.y+=tmp*(p[i].y+p[(i+)%n].y);
area+=tmp;
}
inter.x/=*area;
inter.y/=*area;
return inter;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=; i<n; i++)
{
scanf("%lf%lf",&q[i].x,&q[i].y);
}
Point temp=interity(q,n);
printf("%.2f %.2f\n",temp.x,temp.y);
}
return ;
}