[POJ 1385] Lifting the Stone (计算几何)
题目链接: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 (计算几何)的更多相关文章
- POJ 1385 Lifting the Stone (多边形的重心)
Lifting the Stone 题目链接: http://acm.hust.edu.cn/vjudge/contest/130510#problem/G Description There are ...
- poj 1115 Lifting the Stone 计算多边形的中心
Lifting the Stone Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- Lifting the Stone 计算几何 多边形求重心
Problem Description There are many secret openings in the floor which are covered by a big heavy sto ...
- 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 ...
- Lifting the Stone(求多边形的重心—)
Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- 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(hdu1115)多边形的重心
Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
随机推荐
- AndroidStudio 应用(一)
1.下载安装,用上vpn了都: 2.配置模拟器,出现问题:VT-x is disabled in the BIOS for both all CPU modes (VERR_VMX_MSR_ALL_V ...
- 如何进行oracle capability i/o(压力测试数据库服务器i/o性能)
一 .oracle 有关 IO 信息的相关统计函数 Oracle i/o stack包含hbas,存储相关的交换机.存储物理磁盘.那么oracle建议在应用程序部署的时候,建议去验证i/o避免存在问题 ...
- MyBatis插入多条
<insert id="insertProjectPropertyRelList" parameterType="java.util.List"> ...
- UI-动画
// ------------------UIImageView的动画------------------ // ------------------UIView的动画---------------- ...
- js 编号生成器
编号生成器 前缀: 后缀: 位数: 连续数字 随机字符 范围: ~ 过滤字符: 多个使用,号分割 0123456789 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLM ...
- C++编程新思维中的技巧
1.编译器断言 技巧大致跟后面的一样,都是利用偏特化,但是在C++ 0X里面已经有static_assert,所以感觉这东西也没什么用处了,更多的只是开阔眼界 2.偏特化 就是专门对一个类型去进行特殊 ...
- VS 使用Sql Server 数据库增删改查
/// <summary> /// 执行查询语句,返回DataSet /// </summary> /// <param name="SQLString&quo ...
- ubuntu双网卡bonding配置(转)
1.安装软件 apt-get install ifenslave 2.修改配置文件 /etc/network/interfaces auto lo iface lo inet loopback ifa ...
- ScalaTour 2.函数
/** * 1. case class与模式匹配 */ object TestFunction extends App{ def value(expr:Expr): Int = expr match ...
- TFS Build Error: CSC : fatal error CS0042: Unexpected error creating debug information file 'xxxx.PDB'
CSC : fatal error CS0042: Unexpected error creating debug information file 'xxxx.PDB' -- 'c:\Builds\ ...