[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 ...
随机推荐
- TKinter之窗口美化 窗口大小、图标等
设置窗口大小.设置窗口标题.设置窗口图标 效果图: 代码示例: #!/usr/bin/env python # _*_ coding:utf-8 _*_ from Tkinter import * r ...
- ExtJs学习笔记之Window组件
Window窗体组件 window是一个指定的打算作为一个应用程序窗口的面板,默认窗口是浮动的,resizable, 并且draggable,默认的,窗体靠document.body呈现. 1.示例: ...
- asp.net生成PDF文件 (1)
asp.net生成PDF文件 (1) 这个是例子是网上淘来的,哈哈,很有用的! 首先要到网上下载itextsharp.dll,然后添加引用,主程序如下: 1 2 3 4 5 6 7 8 9 10 11 ...
- 详解MySQL大表优化方案( 转)
当MySQL单表记录数过大时,增删改查性能都会急剧下降,可以参考以下步骤来优化: 单表优化 除非单表数据未来会一直不断上涨,否则不要一开始就考虑拆分,拆分会带来逻辑.部署.运维的各种复杂度,一般以整型 ...
- 移动设备上的媒体查询 CSS media queries for mobile device
CSS的媒体查询虽然在传统的互联网页面可能发挥的余地不是很大,但是自从苹果和安卓的风靡之后,移动平台上的web开发变得越来越流行了,同时CSS的媒体查询可谓派上了大用场了. 以下为翻译内容,原文来自这 ...
- SQL Server 2008中SQL增强之三:Merge(在一条语句中使用Insert,Update,Delete) 一条语句实现两表同步(添加、删除、修改)
MERGE 目标表 USING 源表 ON 匹配条件 WHEN MATCHED THEN 语句 WHEN NOT MATCHED THEN 语句; http://www.chinaz.com/prog ...
- Redis-sentinel监控
Sentinel介绍 Redis的 Sentinel 系统用于管理多个Redis服务器, 该系统执行以下三个任务: 监控(Monitoring) 提醒(Notification) 自动故障迁移(Aut ...
- httpd安装
1.软件准备 http://apache.fayea.com/apache-mirror//apr/apr-1.5.1.tar.gz http://apache.fayea.com/apache-mi ...
- zabbix安装,关闭SELinux
一.缘由 在安装zabbix的时候,按照官网的Zabbix Manual一路跑下来,zabbix的dashboard提示:zabbix server is not running the inform ...
- Shell 重定向 &>file,2>&1,1>&2 的区别
Shell上:0表示标准输入1表示标准输出2表示标准错误输出> 默认为标准输出重定向,与1>相同2>&1 意思是 把标准错误输出重定向到标准输出1>&2 意思是 ...