hdu 1115 Lifting the Stone【多边形重心】
来源:互联网 发布:数据透视表视频教程 编辑:程序博客网 时间:2024/05/23 12:04
题目链接: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;}
0 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【多边形重心】
- 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 多边形重心 模板体
- 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 (求多边形的重心)
- hdu 1115 Lifting the Stone【求多边形重心】
- hdu acm 1115 Lifting the Stone(多边形重心)
- hdu-1115 Lifting the Stone(求多边形的重心)
- JZOJ4986. 神秘物质
- nova-api源码分析(一)--------创建虚机流程
- 【郑轻OJ】1405--Red and Black(dfs)
- 选夫婿2
- 20170227 总要有个开始
- hdu 1115 Lifting the Stone【多边形重心】
- 把字符串转为整数
- 00003 不思议迷宫.0010.1.1.2:csb解析显示
- kde桌面的小问题
- Java 并发开发:内置锁 Synchronized
- 二分搜索最左位置
- [Leetcode] #73 Set Matrix Zeroes
- Spring Boot 项目发布到 Tomcat 服务器
- UML类图几种关系的总结