[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 ...
随机推荐
- 学习Python遇到的那些坑
1. 初始化一个类,这个方法名必须为”__init__(object)“.顺便提一下,两边的下划线是均是2个 2. 每个程序块都要使用冒号!!!! 3. 如果程序中使用了非英文字符,需要在Python ...
- com.opensymphony.module.sitemesh.filter.PageFilter 装饰页面
1.web.xml中配置: <filter> <filter-name>sitemeshFilter</filter-name> <filter-class& ...
- Http状态码301和302概念简单区别
1.什么是301重定向? 301重定向/跳转一般,表示本网页永久性转移到另一个地址. 301是永久性转移(Permanently Moved),SEO常用的招式,会把旧页面的PR等信息转移到新页面: ...
- 06socket编程
socket可以看成是用户进程与内核网络协议栈的编程接口. socket不仅可以用于本机的进程间通信,还可以用于网络上不同主机的进程间通信. IPv4套接口地址结构通常也称为“网际套接字地址结构”,它 ...
- java 反射机制01
// */ // ]]> java反射机制01 Table of Contents 1 反射机制 2 反射成员 2.1 java.lang.Class 2.2 Constructor 2.3 ...
- 【转】Asp.Net MVC3 简单入门详解过滤器Filter
原文地址:http://www.cnblogs.com/boruipower/archive/2012/11/18/2775924.html 前言 在开发大项目的时候总会有相关的AOP面向切面编程的组 ...
- Dell R410 broadcom网卡驱动更新失败
问题描述: 最近遇到一个Dell R410 broadcom网卡驱动更新失败的问题.从官网上下载的驱动在安装的过程中都会自己回滚回来,很是困惑. 尝试解决: Dell官网现在提供的驱动一般最少有两种格 ...
- Python 迭代删除重复项,集合删除重复项
1. 迭代删除重复项:先排序列表项,然后通过新迭代(not in)去除重复项,分片打印 def sanitize(time_string): if '-' in time_string: splitt ...
- showdialog窗体不在任务栏显示的问题处理
场景: c#开发的windows窗体用showdialog弹出时,在任务栏中 win7系统显示,win xp和win 2003却不显示. 窗体的ShowInTaskbar已设置为True. 解决: 在 ...
- oracle学习笔记(二)设置归档模式
设置归档模式(mount状态) ALTER database ARCHIVELOG; //关闭数据库 shutdown immediate //启动数据库到mount状态 startup mount ...