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. HDU 6370 dfs+并查集

    Werewolf Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...

  2. POJ 3013 【需要一点点思维...】【乘法分配率】

    题意: (这题明显感觉自己是英语渣) 给n个点从1到n标号,下面一行是每个点的权,另外给出m条边,下面是每条边的信息,两个端点+权值,边是无向边.你的任务是选出一些边,使这个图变成一棵树.这棵树的花费 ...

  3. linux下查看哪个进程占用内存多

    1.用top命令 1.top top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器 可以直接使用top命令后,查看%MEM的内容.可以 ...

  4. 临远大神,你为啥要建立一个 TASK表。HumanTaskDTO

    临远大神,你为啥要建立一个 TASK表.HumanTaskDTO HumanTask这张表的作用是什么. 为了实现理想中的任务中心.TaskCenter. 首先,工作流可能会完全不包含任何人工节点,全 ...

  5. Oracle 行转列小结

    近期在工作中.对行转列进行了应用,在此做一个简单的小结. 转换步骤例如以下:     1.创建表结构 CREATE TABLE RowToCol ( ID NUMBER(10) not null, U ...

  6. [Angular] Expose Angular Component Logic Using State Reducers

    A component author has no way of knowing which state changes a consumer will want to override, but s ...

  7. spring理解一

    spring基本工作原理例如以下: 1.查找bean配置文件 2.载入bean配置文件并解析生成中间表示BeanDefinition 3.注冊beanDefinition 4.假设是单例或lazy-i ...

  8. STL 源代码剖析 算法 stl_algo.h -- nth_element

    本文为senlie原创.转载请保留此地址:http://blog.csdn.net/zhengsenlie nth_element ---------------------------------- ...

  9. 一起talk C栗子吧(第一百二十一回:C语言实例--线程知识体系图)

    各位看官们.大家好,上一回中咱们说的线程属性的样例.这一回咱们说的样例是:线程知识体系图.闲话休提.言归正转. 让我们一起talk C栗子吧! 我们在前面的章回中介绍了与线程相关的知识,在今天的章回中 ...

  10. Android修改签名

    #!/bin/shtmp=~/temp.apkcp "$1" "$tmp"zip -d "$tmp" META-INF/\*jarsigne ...