hdu 1115 Lifting the Stone【多边形重心】
2017-02-27 22:16
381 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1115
题意:给你一个多边形,让你求他的重心
解析:多边形重心公式,即把多边形分成多个三角形,然后是三角形的重心的权重和
题意:给你一个多边形,让你求他的重心
解析:多边形重心公式,即把多边形分成多个三角形,然后是三角形的重心的权重和
#include <cmath> #include <algorithm> #include <iostream> #include <cstdio> #include <vector> #include <cstring> using namespace std; const int maxn = 1000000+10; const double eps = 1e-5; struct point { double x; double y; point() {} point(double _x,double _y) { x = _x; y = _y; } }a[maxn]; double x_mul(point p0,point p1,point p2) { return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y); } point gravity(int n) { point res = {0,0}; double tmp = 0; for(int i=0;i<n;i++) { double s = x_mul(point(0,0),a[i],a[(i+1)%n]); tmp += s; res.x += s*(a[i].x+a[(i+1)%n].x); res.y += s*(a[i].y+a[(i+1)%n].y); } res.x = res.x/tmp/3.0; res.y = res.y/tmp/3.0; return res; } int main(void) { int n,t; cin>>t; while(t--) { scanf("%d",&n); for(int i=0;i<n;i++) scanf("%lf %lf",&a[i].x,&a[i].y); point ans = gravity(n); printf("%.2f %.2f\n",ans.x,ans.y); } return 0; }
相关文章推荐
- hdu 1115 Lifting the Stone【多边形重心】
- HDU 1115 Lifting the Stone (多边形重心)
- hdu 1115 Lifting the Stone 多边形的重心
- hdu 1115 Lifting the Stone 多边形的重心
- HDU 1115 Lifting the Stone(多边形重心)
- hdu1115 Lifting the Stone(几何,求多边形重心模板题)
- HDU 1115 Lifting the Stone(求多边形重心)
- hdu 1115 Lifting the Stone【求多边形重心】
- HDU 1115 Lifting the Stone ( 求多边形的重心:叉积)
- hdu-1115 Lifting the Stone(求多边形的重心)
- 多边心重心[nyoj 3 多边形重心问题, hdu 1115 Lifting the Stone]
- HDU-#1115 Lifting the Stone(多边形重心)
- HDU 1115 Lifting the Stone 多边形的重心
- hdu_1115_Lifting the Stone(求多边形重心)
- hdu1115 Lifting the Stone (多边形重心)
- hdu_1115_Lifting the Stone(求多边形重心)
- HDU 1115 Lifting the Stone (求多边形的重心)
- hdu 1115 Lifting the Stone 多边形的重心
- hdu 1115:Lifting the Stone(计算几何,求多边形重心。 过年好!)
- HDU1115 Lifting the Stone (求多边形的重心)