[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 ...
随机推荐
- jsoncpp 生成 json 字符串
Json::Value root; Json::Value arrayObj; Json::Value item; for (int i=0; i<10; i++) { item["k ...
- 查看SqlServer的内存使用情况
上一篇提到动态T-SQL会产生较多的执行计划,这些执行计划会占用多少内存呢?今天从徐海蔚的书中找到了答案.动态视图不仅可以查到执行计划的缓存,数据表的页面缓存也可以查到,将SQL整理一下,做个标记. ...
- 一个项目中说系统分为表现层、控制层、逻辑层、DAO层和最终数据库五层架构-转
表现层就是看到的东西,比如你现在看到的当前页面控制层就将你的请求从页面传到后台代码逻辑层就是处理你的请求的代码DAO层就是将数据存到数据库中的代码数据库就是数据库了,存东西用的 ,DAO层就是将访问数 ...
- Oracle视图详解
转载自:http://blog.itpub.net/29785807/viewspace-1270120/ 一. 视图的定义 视图(view),也称虚表, 不占用物理空间,这个也是相对概念,因为视图本 ...
- sql访注入
http://www.dewen.org/q/6154/java%E7%A8%8B%E5%BA%8F%E9%98%B2%E6%AD%A2sql%E6%B3%A8%E5%85%A5%E7%9A%84%E ...
- DDD学习笔记一
由于也是初学DDD,难免有很多不足和认识错误的地方.多数内容来自其他网络资料或者书籍. 参考:http://www.cnblogs.com/Leo_wl/p/4418663.html 希望多多提出宝贵 ...
- uboot在nandflash和norflash是如何运行的
转自:http://www.aiuxian.com/article/p-2796357.html 电子产品如果没有了电,就跟废品没什么区别,是电赋予了他们生命,然而程序则是他们的灵魂. 小时候一直很好 ...
- SQL Server 2012 数据库备份
既能备份到网络中的共享文件夹中,也能备份到本地 USE [AdventureWorks2012] GO /****** Object: StoredProcedure [dbo].[pr_BatchB ...
- 黄聪:优化清理WordPress数据库wp_options表(缩小autoload体积)
使得wp_options表变得庞大的重要原因:无用的RSS Feed Cache.如果你在wp_options表中发现了大量option_name包含“_transient”的数据,那就是它没跑了.先 ...
- 黄聪:wordpress如何使用wp_rewrite实现自定义伪静态,非301重定向。
今天,想通过wordpress实现 http://hcsem.com/a?h-1 伪静态为 http://hcsem.com/a-1.html 找了很多资料,终于搞定. 只需要在functions.p ...