【计算几何初步:多边形中心】【HDU1115】Lifting the Stone
一.质点系重心公式
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的更多相关文章
- hdu1115 Lifting the Stone(几何,求多边形重心模板题)
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:pid=1115">http://acm.hdu.edu.cn/showproblem.php ...
- hdu 1115:Lifting the Stone(计算几何,求多边形重心。 过年好!)
Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- poj 1115 Lifting the Stone 计算多边形的中心
Lifting the Stone Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- Lifting the Stone(hdu1115)多边形的重心
Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- Lifting the Stone(求多边形的重心—)
Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- Lifting the Stone(多边形重心)
Lifting the Stone Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- POJ 1385 Lifting the Stone (多边形的重心)
Lifting the Stone 题目链接: http://acm.hust.edu.cn/vjudge/contest/130510#problem/G Description There are ...
- hdu 1115 Lifting the Stone 多边形的重心
Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- Lifting the Stone(hdoj1115)
Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- (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 ...
随机推荐
- 图片轮播插件 Slides-SlidesJS-3
图片轮播插件 Slides-SlidesJS-3 demo document 地址: http://slidesjs.com/
- JavaScript ----------------- 原型式继承
思想:借助原型可以基于已有的对象创建新对象,同时还不必因此创建自定义类型.为了达到这个目的,看看下面的实现方式 function object(o){ function F(){ } F.protot ...
- uva 12100 Printer Queue
The only printer in the computer science students' union is experiencing an extremely heavy workload ...
- UVALive 4119 Always an integer (差分数列,模拟)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Always an integer Time Limit:3000MS M ...
- git add和被ignore的文件
如果有如下的目录结构: workspace tree | --------------------- | | hello.c ...
- Android网络连接的两种方法:apache client和httpurlconnection的比较
另见http://blog.csdn.net/mingli198611/article/details/8766585 在官方blog中,android工程师谈到了如何去选择apache client ...
- sessionStorage 、localStorage 和 cookie 之间的区别(转)
essionStorage .localStorage 和 cookie 之间的区别(转) 2012-05-08 14:29:19| 分类: HTML5CSS3WEBAPP|举报|字号 订阅 ...
- C语言中的宏定义
目录(?)[-] 简单宏定义 带参数的宏 运算符 运算符 宏的通用属性 宏定义中圆括号 创建较长的宏 较长的宏中的逗号运算符 宏定义中的do-while循环do 空操作的定义 预定义宏 C语言中常用的 ...
- Qt Project的持续集成方案
作者:齐亮链接:http://www.zhihu.com/question/24314354/answer/27547787来源:知乎著作权归作者所有,转载请联系作者获得授权. PETER HARTM ...
- [置顶] 玩转Eclipse — 自动注释插件JAutodoc
代码注释是一种良好的编程习惯.不管对于他人还是自己,注释都有助于代码的阅读和理解.手动添加注释,是一个非常费时和繁琐的工作,严重影响软件开发效率,这也是绝大多数程序员不愿添加注释的主要原因.JAuto ...