题目链接:http://poj.org/problem?id=1385

题目大意:给你一个多边形的点,求重心。

首先,三角形的重心: ( (x1+x2+x3)/3 , (y1+y2+y3)/3 )

然后多边形的重心就是将多边形划分成很多个三角形,以三角形面积为权值,将每个三角形的重心加权平均。

注意:

pair<double,double>会MLE。。

fabs会损失精度?(这个我也不知道),因此在用向量叉积求三角形面积的时候最好是直接让面积求出来就是正的。。否则fabs就WA了。。。

代码:

 #include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long LL;
#define EPS 1e-8
#define X first
#define Y second typedef struct _POINT{ // 用pair<double,double>会MLE!!
double first;
double second;
}POINT; typedef POINT VECTOR;
double operator*(VECTOR x,VECTOR y){
double res;
res = x.X*y.Y-x.Y*y.X ;
return res;
}
VECTOR operator-(POINT x,POINT y){
VECTOR res;
res.X = x.X - y.X ;
res.Y = x.Y - y.Y ;
return res;
} const int MAX_N = ;
int T,N;
POINT pt[MAX_N]; POINT getCenter(POINT points[],int n){
POINT res;
double area,areamulx,areamuly;
area = 0.0; areamulx = 0.0 ; areamuly = 0.0;
for(int i=;i<n-;i++){
VECTOR v1 = points[i]-points[];
VECTOR v2 = points[i+]-points[i]; // 后面如果fabs会损失精度。。
double tarea = v1 * v2 / 2.0;
area += tarea;
areamulx += (points[].X+points[i].X+points[i+].X)*tarea;
areamuly += (points[].Y+points[i].Y+points[i+].Y)*tarea;
}
res.X = areamulx / (3.0*area);
res.Y = areamuly / (3.0*area);
return res;
} int main(){
scanf("%d",&T);
while( T-- ){
scanf("%d",&N);
for(int i=;i<N;i++){
scanf("%lf%lf",&pt[i].X,&pt[i].Y);
}
POINT ans = getCenter(pt,N);
printf("%.2lf %.2lf\n",ans.X+EPS,ans.Y+EPS);
}
return ;
}

[POJ 1385] Lifting the Stone (计算几何)的更多相关文章

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

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

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

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

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

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

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

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

  5. Lifting the Stone(hdoj1115)

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

  6. (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 ...

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

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

  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(hdu1115)多边形的重心

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

随机推荐

  1. linux更改启动级别后,无法启动的问题解决

    装好之后,配置好IP,启动后也能上网了,然后我修改了系统的启动级别(默认为3,我改为了5),意思是让他能够启动桌面. 我是这么设置的: 1.vi命令打开/etc/inittab文件,可以看到如下描述 ...

  2. c#无限级分类

    data: [ { text: '节点1', icon: myaccount, children: [ { text: '节点1.1', icon: archives }, { text: '节点1. ...

  3. 关于ORALCE一个表空间的数据导入到另一个表空间的方法(原创)

    用户:   whnaproject     所属表空间: whnaproject 新用户   : wniec            所属新表空间: wniec 要求:将用户whnaproject中的数 ...

  4. 好的博客mark

    1. http://blog.csdn.net/zqixiao_09/article/month/2016/03 涉及面光,包括上层/底层, uboot/kernel/rootfs/driver.

  5. cent os下面的基本配置操作

    二,修改Linux分辨率命令行 在root用户模式下,输入$ vi /boot/grub/grub.conf(路径可能会不一样,也可以是 /etc/grub.conf),打开grub.conf文件 我 ...

  6. PHP加密解密类

    <?php class Mypass { static function encrypt($data, $key){ $key = md5($key); $x = 0; $len = strle ...

  7. class 文件与dex文件区别 (dvm与jvm区别)及Android DVM介绍

    区别一:dvm执行的是.dex格式文件  jvm执行的是.class文件   android程序编译完之后生产.class文件,然后,dex工具会把.class文件处理成.dex文件,然后把资源文件和 ...

  8. PC-Lint安装配置与集成到VS2010

    第一篇 PC-lint 9 安装及配置教程 1.从这里下载PC-lint.9.0e.rar,解压缩(目录中的patch文件夹不用,因为它只能将PC-lint升级到9.0e ) 2.点击pclint9s ...

  9. 如何实现一个malloc

    任何一个用过或学过C的人对malloc都不会陌生.大家都知道malloc可以分配一段连续的内存空间,并且在不再使用时可以通过free释放掉.但是,许多程序员对malloc背后的事情并不熟悉,许多人甚至 ...

  10. [JS]Javascript的函数总结

    Javascript中不存在函数重载,同名的函数将被最后一个覆盖. function test(a,b){ this.x = 1;} function test(a){ this.x = 2;} fu ...