1.质量集中在顶点上。n个顶点坐标为(xi,yi),质量为mi,则重心(∑( xi×mi ) / ∑mi, ∑( yi×mi ) / ∑mi)

2.质量分布均匀。这个题就是这一类型,算法和上面的不同。

特殊地,质量均匀的三角形重心:(( x0 + x1 + x2 ) / 3,Y = ( y0 + y1 + y2 ) / 3)

以(0,0)为顶点三角剖分之后求三角形重心,把重心连起来转换成质量集中在顶点上的情况求解即可

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
const int N=1000005;
int T,n;
double am;
struct dian
{
double x,y,v;
dian(double X=0,double Y=0)
{
x=X,y=Y;
}
dian operator + (const dian &a) const
{
return dian(x+a.x,y+a.y);
}
dian operator - (const dian &a) const
{
return dian(x-a.x,y-a.y);
}
dian operator * (const double &a) const
{
return dian(x*a,y*a);
}
dian operator / (const double &a) const
{
return dian(x/a,y/a);
}
}p[N],a;
int read()
{
int r=0,f=1;
char p=getchar();
while(p>'9'||p<'0')
{
if(p=='-')
f=-1;
p=getchar();
}
while(p>='0'&&p<='9')
{
r=r*10+p-48;
p=getchar();
}
return r*f;
}
double cj(dian a,dian b)
{
return a.x*b.y-a.y*b.x;
}
int main()
{
T=read();
while(T--)
{
n=read();am=0,a.x=0,a.y=0;
for(int i=1;i<=n;i++)
p[i].x=read(),p[i].y=read();
p[n+1]=p[1];
for(int i=2;i<=n+1;i++)
{
double mj=cj(p[i-1],p[i]);
am+=mj,a=a+(p[i-1]+p[i])*mj;
}
printf("%.2f %.2f\n",a.x/am/3,a.y/am/3);
}
return 0;
}

hdu1115【多边形求重心模板】的更多相关文章

  1. Lifting the Stone(hdu1115)多边形的重心

    Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...

  2. 多边形求重心 HDU1115

    http://acm.hdu.edu.cn/showproblem.php?pid=1115 引用博客:https://blog.csdn.net/ysc504/article/details/881 ...

  3. hdu-1115 计算几何 求重心 凸多边形 面积

    思想是分割成三角形,然后求三角形的重心.那么多边形重心就是若干个三角形的重心带权求中心,可以用质点质心公式. #include <cstdio> #include <iostream ...

  4. Lifting the Stone 计算几何 多边形求重心

    Problem Description There are many secret openings in the floor which are covered by a big heavy sto ...

  5. hdu1115 Lifting the Stone(几何,求多边形重心模板题)

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:pid=1115">http://acm.hdu.edu.cn/showproblem.php ...

  6. HDU1115&&POJ1385Lifting the Stone(求多边形的重心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1115# 大意:给你个n,有n个点,然后给你n个点的坐标,求这n个点形成的多边形的重心的坐标. 直接套模 ...

  7. hdu1115(计算多边形几何重心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1115 题意:给出一些点,求这些点围成的多边形的重心: 思路: 方法1:直接分别求所有点的x坐标的平均值 ...

  8. Lifting the Stone(求多边形的重心—)

    Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...

  9. POJ 1385 Lifting the Stone (多边形的重心)

    Lifting the Stone 题目链接: http://acm.hust.edu.cn/vjudge/contest/130510#problem/G Description There are ...

随机推荐

  1. Python数据分析常用的库总结

    Python之所以能够成为数据分析与挖掘领域的最佳语言,是有其独特的优势的.因为他有很多这个领域相关的库可以用,而且很好用,比如Numpy.SciPy.Matploglib.Pandas.Scikit ...

  2. Edit Distance(动态规划,难)

    Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2 ...

  3. Java重写equals方法和hashCode方法

    package com.ddy; public class User {     private Integer id;     private String name;     private St ...

  4. grunt安装,配置记录

    进了新的公司,需要重构一个项目,从头开始.本人患懒癌已久,一直没有写博客的打算,也是因为资质还比较浅,写不出什么富有涵养的内容,后来想了想,就当自己的笔记吧.这次从新开始,未尝不是一个博客开始的好时机 ...

  5. jq自定义裁剪,代码超级简单,易修改

    1.自定义宽高效果 1.html 代码  index.html <!DOCTYPE html> <html lang="en"> <head> ...

  6. Broadcom的消息机制

    在Broadcom中提供了自己的消息机制,有两种消息形式:Request/Response and Event(事件) Request/Response消息:进程之间的通信都是通过smd,所有的消息都 ...

  7. [javase学习笔记]-9.2 单继承与多重继承

    这一节我们来看java中的单继承和多重继承. 在java语言中,支持的是单继承,不直接支持多继承,可是对C++中的多继承进行了改良. 那么什么是单继承和多继承呢? 单继承:一个子类仅仅能有一个直接父类 ...

  8. Spring4.0MVC学习资料,注解自己主动扫描bean,自己主动注入bean(二)

    Spring4.0的新特性我们在上一章已经介绍过了. 包含它对jdk8的支持,Groovy Bean Definition DSL的支持.核心容器功能的改进,Web开发改进.測试框架改进等等.这张我们 ...

  9. Linux下进程信息的深入分析

    这里我们主要介绍进程的状态,进程的状态可以通过/proc/PID/status来查看,也可以通过/proc/PID/stat来查看. 如果说到工具大家用的最多的ps也可以看到进程的信息.这里我们通过/ ...

  10. EXCEPT(差集)集合运算

    在集合论中,集合A与B的差集(A-B)是由属于集合A,但不属于集合B的元素组成的集合.可以认为两个集合的差A-B就是从A中减去B中也属于A的元素. 在T-SQL中,集合之差是用EXCEPT集合运算实现 ...