一.质点系重心公式

x=(x1*m1+x2*m2+x3*m3.....xn*mn)/M  (M=m1+m2+m3+m4...+mn)

二.三角形重心

可直接求得,但在多边形剖分中 各三角形的质点的质量大小不一样 质量大小等于三角形面积.

三.多边形重心

三角形剖分+任意点的三角形剖分+三角形重心+质点系重心公式+任意点的三角形剖分

所以很容易知道一种很优美的计算公式(看代码)

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#define oo 0x13131313
#define maxn 1000000+10
using namespace std;
struct point{
double x,y;
};
point A[maxn];
int N;
double ansX,ansY;
double Sarea;
void input()
{
ansX=0;ansY=0;Sarea=0;
cin>>N;
for(int i=1;i<=N;i++)
{
scanf("%lf%lf",&A[i].x,&A[i].y);
}
}
void init()
{
freopen("a.in","r",stdin);
freopen("a.out","W",stdout);
}
void get_Sarea()
{
for(int i=1;i<=N;i++)
{
int j=i+1;
if(j==N+1) j=1;
Sarea+=(A[i].x*A[j].y-A[j].x*A[i].y)*0.5;
}
}
void get_ansXansY()
{
for(int i=1;i<=N;i++)
{
int j=i+1;
if(j==N+1) j=1;
double area=(A[i].x*A[j].y-A[j].x*A[i].y)*0.5;
ansX+=area*(A[i].x+A[j].x); // area*(A[i].x+A[j].x+0)/3 质点的重量
ansY+=area*(A[i].y+A[j].y);
}
ansX=ansX/(3*Sarea);
ansY=ansY/(3*Sarea);
}
int main()
{
int T;
cin>>T;
while(T--)
{
input();
get_Sarea();
get_ansXansY();
printf("%.2lf %.2lf\n",ansX,ansY);
}
return 0;
}

【计算几何初步:多边形中心】【HDU1115】Lifting the Stone的更多相关文章

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

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

  2. hdu 1115:Lifting the Stone(计算几何,求多边形重心。 过年好!)

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

  3. poj 1115 Lifting the Stone 计算多边形的中心

    Lifting the Stone Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

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

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

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

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

  6. Lifting the Stone(多边形重心)

    Lifting the Stone Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

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

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

  8. hdu 1115 Lifting the Stone 多边形的重心

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

  9. Lifting the Stone(hdoj1115)

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

  10. (hdu step 7.1.3)Lifting the Stone(求凸多边形的重心)

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

随机推荐

  1. J2EE之普通类载入web资源文件的方法

    在WEB中普通类并不能像Servlet那样通过this.getServletContext().getResourceAsStream()获取web资源,须要通过类载入器载入,这里有两种方式,这两种方 ...

  2. [Protractor] Running tests on multiple browsers

    Testing your AngularJS application on multiple browsers is important, and Protractor offers this abi ...

  3. Git 多人协作的工作模式

    多人协作 148次阅读 当你从远程仓库克隆时,实际上Git自动把本地的master分支和远程的master分支对应起来了,并且,远程仓库的默认名称是origin. 要查看远程库的信息,用git rem ...

  4. 19. Crontab

    一.Crontab 的使用 1.crontab 命令参数: -e   编辑该用户的计时器设置 -l 列出该用户的计时器设置 -r 删除该用户的计时器设置-u<用户名称> 指定要设定计时器的 ...

  5. border-radius讲解2

    一:border-radius只有一个取值时,四个角具有相同的圆角设置,其效果是一致的: .demo { border-radius: 10px; } 其等价于: .demo{ border-top- ...

  6. Oracle自治事务

    定        义: Autonomous transactions are independent transactions that can be called from within anot ...

  7. Visual Studio .NET、.NET Framework和C#之间的联系

    Visual Studio .NET是一种集成开发环境(IDE),它包含3种高级程序设计语言,C#就是其中的一种:Visual Studio .NET之所以能把这三种语言有机结合起来并具有与平台无关的 ...

  8. Java的反射机制及应用实例

    一:什么是反射机制 简单的来说,反射机制指的是程序在运行时能够获取自身的信息.在Java中,只要给定类的名字,那么就可以通过反射机制来获得类的所有信息. 二:哪里用到反射机制 我们用过一些知识,但是并 ...

  9. Tomcat学习笔记 - 错误日志 - NetBeans配置tomcat出错情况总结 -- 尚未授予访问 Tomcat 服务器的权限。请在服务器管理器的 Tomcat 定制器中设置 "manager-script" 角色的正确用户名和口令。 有关详细信息, 请查看服务器日志。

    错误描述: 发布时控制台出现: 部署错误: 尚未授予访问 Tomcat 服务器的权限.请在服务器管理器的 Tomcat 定制器中设置 "manager-script" 角色的正确用 ...

  10. 看看国外的javascript题目,你能全部做对吗?(分享)

    本文转自@Aaron的博客,拿过来分享一下.原文:看看国外的javascript题目,你能全部做对吗? 题目一: (function(){ return typeof arguments; })(); ...