标签:des style blog color java os io strong
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5370 Accepted Submission(s):
2239
#include<stdio.h> #include<stdlib.h> /*==================================================*| 求多边形重心 | INIT: pnt[]已按顺时针(或逆时针)排好序; | CALL: res = bcenter(pnt, n); \*==================================================*/ struct point { double x, y; }pnt[1000005],res; point bcenter(point pnt[], int n)//重心 { point p, s; double tp, area = 0, tpx = 0, tpy = 0; p.x = pnt[0].x; p.y = pnt[0].y; for (int i = 1; i <= n; ++i) { // point: 0 ~ n-1 s.x = pnt[(i == n) ? 0 : i].x; s.y = pnt[(i == n) ? 0 : i].y; tp = (p.x * s.y - s.x * p.y);//叉乘 area += tp / 2; tpx += (p.x + s.x) * tp; tpy += (p.y + s.y) * tp; p.x = s.x; p.y = s.y; } s.x = tpx / (6 * area); s.y = tpy / (6 * area); return s; } int main() { int T,N,i; scanf("%d",&T); while(T--) { scanf("%d",&N); for(i=0;i<N;i++) { scanf("%lf%lf",&pnt[i].x,&pnt[i].y); } res=bcenter(pnt, N); printf("%0.2lf %0.2lf\n",res.x,res.y); } return 0; }
Lifting the Stone(hdu1115)多边形的重心,布布扣,bubuko.com
Lifting the Stone(hdu1115)多边形的重心
标签:des style blog color java os io strong
原文地址:http://www.cnblogs.com/yuyixingkong/p/3912433.html