题目链接: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. 目录操作工具类 CopyDir.java

    package com.util; import java.io.*; /** * 1,建立目的目录. 2,遍历源目录. 3,遍历过程中,创建文件或者文件夹. 原理:其实就是改变了源文件或者目录的目录 ...

  2. javascript url 相关函数(escape/encodeURL/encodeURIComponent区别)

    JS获取url参数及url编码.解码 完整的URL由这几个部分构成:scheme://host:port/path?query#fragment ,各部分的取法如下: window.location. ...

  3. 网页颜色RGB记法和16进制记法转化方法

    A=>10,B=>11,C=>12,D=>13,E=>14,F=>15 看一个例子: 254,112,85 255/16 等于 15 余 14 那么它对应的应该是F ...

  4. android学习笔记五——AutoCompleteTextView

    AutocompleteTextview ==> 使用比较容易,只需要为其设置一个Adapter,该Adapter封装其需要预设的文本内容. 如下所示实例: <RelativeLayout ...

  5. SQL Server附加数据库文件出错

    场景: 新装一台数据库服务器,装好后,附加数据库时出错.附加前的数据库架构没有在新服务器上安装.新服务器上只有默认dbo架构. 解决: 以windows身份验证登录,附加正常. 错误码可能为5120. ...

  6. c++ 迭代器库

    来自http://zh.cppreference.com/w/cpp/iterator 迭代器库提供了5种迭代器的定义,同时还提供了迭代器特征.适配器及其相关的工具函数. 迭代器共有5种:InputI ...

  7. 【SQL Server】系统学习之三:逻辑查询处理阶段-六段式

    一.From阶段 针对连接说明: 1.笛卡尔积 2.on筛选器 插播:unknown=not unknuwn 缺失的值: 筛选器(on where having)把unknown当做FALSE处理,排 ...

  8. PLSQL_性能优化系列07_Oracle Parse Bind Variables解析绑定变量

    2014-09-25 Created By BaoXinjian

  9. OAF_架构MVC系列3 - View的概述(概念)

    2014-06-18 Created By BaoXinjian

  10. 安装Android SDK和ADT步骤和遇到的问题

    http://894503895.diandian.com/post/2012-05-16/18695648 1.安装eclipse.下载地址:http://www.eclipse.org/downl ...