hdu 1115 Lifting the Stone
来源:互联网 发布:主力控盘指标公式源码 编辑:程序博客网 时间:2024/05/11 13:25
题目地址
题目大意:给定n个点的坐标,求n边形的重心
解题思路:选定任意一点作为定点(坐标原点)为每个三角形的一个顶点,将n边形分成n个三角形,n边形的重心=(每个三角形的重心*每个三角形的面积)/面积和
#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>#include <cstring>#include <queue>#include <string>#include <map>#include <stack>#include <list>#include <set>using namespace std;const int maxn = 1e6+100;struct Point{ double x; double y;}p[maxn],gra;int main(){ int n,t; scanf("%d",&t); while(t--) { scanf("%d",&n); for(int i = 0; i < n; i++) scanf("%lf%lf",&p[i].x,&p[i].y); double area = 0.; gra.x = gra.y = 0.; p[n] = p[0]; for(int i = 0; i < n; i++) { area += (p[i].x*p[i+1].y-p[i].y*p[i+1].x); gra.x += (p[i].x*p[i+1].y-p[i].y*p[i+1].x)*(p[i].x+p[i+1].x); gra.y += (p[i].x*p[i+1].y-p[i].y*p[i+1].x)*(p[i].y+p[i+1].y); } gra.x /= 3*area; gra.y /= 3*area; printf("%.2lf %.2lf\n",gra.x,gra.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-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 (多边形重心)
- openstack 之 ceilometer: Sample
- 1160 不能被整除的数【容斥原理】
- Kurento应用开发指南(以Kurento 6.0为模板) 之六:kurento架构
- 图片整理(字符串排序)
- 快速排序的基本思想及Java实现
- hdu 1115 Lifting the Stone
- 对于python中的self,cls,decorator的理解
- CSS——样式表;选择器;优先级
- UVa 1220:Party at Hali-Bula(DP)
- CAShapeLayer和CAGradientLayer 详解
- HTML 超文本 布局
- 将目标文件分为程序段与数据段两大类的原因
- wfs服务查询详解
- Kurento应用开发指南(以Kurento 6.0为模板) 之七:Kurento API 参考