把每个三角形看成一个质点,坐标就是各自的重心,

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cassert>
#include<iomanip>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f; struct point{
double x,y;
/* point(){};
point(double _x,double _y):x(_x),y(_y){}
point operator *(double p)
{
return point(x*p,y*p);
}
double operator *(point p)
{
return x*p.x+y*p.y;
}
point operator /(double p)
{
return point(x/p,y/p);
}
point operator +(point p)
{
return point(x+p.x,y+p.y);
}
point operator -(point p)
{
return point(x-p.x,y-p.y);
}*/
};
point p[N],s[N];
int n;
inline bool zero(double x)
{
return fabs(x)<eps;
}
double dir(point p1,point p2,point p3)
{
return (p3.x-p1.x)*(p2.y-p1.y)-(p3.y-p1.y)*(p2.x-p1.x);
}
double dis(point p1,point p2)
{
return sqrt((p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y));
}
bool comp(point p1,point p2)
{
double te=dir(p[],p1,p2);
if(te<)return ;
if(zero(te)&&dis(p[],p1)<dis(p[],p2))return ;
return ;
}
void Graham()
{
for(int i=;i<n;i++)
if(p[i].x<p[].x||(p[i].x==p[].x&&p[i].y<p[].y))
swap(p[],p[i]);
sort(p+,p+n,comp);
p[n]=p[];
s[]=p[],s[]=p[],s[]=p[];
int top=;
for(int i=;i<=n;i++)
{
while(top>=&&dir(s[top-],s[top],p[i])>=)top--;
s[++top]=p[i];
}
// for(int i=0;i<top;i++)cout<<s[i].x<<" "<<s[i].y<<endl;
point ans;
ans.x=0.0;ans.y=0.0;
double sum=;
for(int i=;i<top;i++)
{
double te=dir(s[],s[i],s[i-]);
sum+=te;
ans.x+=(s[].x+s[i].x+s[i-].x)/*te;
ans.y+=(s[].y+s[i].y+s[i-].y)/*te;
}
ans.x=ans.x/sum;ans.y=ans.y/sum;
if(zero(ans.x))ans.x=0.0;if(zero(ans.y))ans.y=0.0;
cout<<ans.x<<" "<<ans.y<<endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
cout<<setiosflags(ios::fixed)<<setprecision();
while(cin>>n){
if(n<)continue;
for(int i=;i<n;i++)cin>>p[i].x>>p[i].y;
Graham();
}
return ;
}
/*********************
4
0 1
1 1
0 0
1 0
3
1 2
1 0
0 0
7
-4 -4
-6 -3
-4 -10
-7 -12
-9 -8
-3 -6
-8 -3
1
*********************/

uva10002凸包重心的更多相关文章

  1. hdu4273Rescue(三维凸包重心)

    链接 模板题已不叫题.. 三维凸包+凸包重心+点到平面距离(体积/点积)  体积-->混合积(先点乘再叉乘) #include <iostream> #include<cstd ...

  2. [hdu3685]Rotational Painting 凸包 重心

    大致题意: 给出一个多边形,问你有多少种放法可以使得多边形稳定得立在平面上. 先对多边形求重心,在求凸包,枚举凸包的边,如果重心没有在边的范围内,则不行 判断是否在范围内可用点积来判断 #includ ...

  3. hdu 4273 2012长春赛区网络赛 三维凸包中心到最近面距离 ***

    新模板 /* HDU 4273 Rescue 给一个三维凸包,求重心到表面的最短距离 模板题:三维凸包+多边形重心+点面距离 */ #include<stdio.h> #include&l ...

  4. POJ 3528 求三维凸包表面积

    也是用模板直接套的题目诶 //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #include < ...

  5. POJ3528 HDU3662 三维凸包模板

    POJ3528 HDU3662 第一道题 给定若干点 求凸包的表面积,第二题 给定若干点就凸包的面数. 简单说一下三维凸包的求法,首先对于4个点假设不共面,确定了唯一四面体,对于一个新的点,若它不在四 ...

  6. uvalive 4589 Asteroids

    题意:给两个凸包,凸包能旋转,求凸包重心之间的最短距离. 思路:显然两个凸包贴在一起时,距离最短.所以,先求重心,再求重心到各个面的最短距离. 三维凸包+重心求法 重心求法:在凸包内,任意枚举一点,在 ...

  7. HDU 4273

    计算凸包重心到各面的最短距离. 若知道重心,按四面体用体积法即可求出高. 关键在于,多面体重心的求法.这必须把多面体分割成多个四面体来求.下面从多边形的重心说起. 一般来用,对于一个多边形(p0,p1 ...

  8. POJ 2225 / ZOJ 1438 / UVA 1438 Asteroids --三维凸包,求多面体重心

    题意: 两个凸多面体,可以任意摆放,最多贴着,问他们重心的最短距离. 解法: 由于给出的是凸多面体,先构出两个三维凸包,再求其重心,求重心仿照求三角形重心的方式,然后再求两个多面体的重心到每个多面体的 ...

  9. 三维凸包求重心到面的最短距离(HDU4273)

    http://acm.hdu.edu.cn/showproblem.php?pid=4273 Rescue Time Limit: 2000/1000 MS (Java/Others)    Memo ...

随机推荐

  1. Oracle 常见问题汇总

    1.Listener refused the connection with the following error 安装之后如果遇到如下问题状态: 失败 -测试失败: Listener refuse ...

  2. struct初始化

    C语言中struct初始化 • 普通结构体的初始化 假设我们有如下的一段代码,其中已有Student结构体,要求实例化一个Student对象并将其初始化. #include <stdio.h&g ...

  3. Outputting Strings in the Console

    Outputting Strings in the Console #include <windows.h> class Console {public:  enum fore_color ...

  4. 在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连

    在建立与服务器的连接时出错.在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连 sql server服务器sqlserver远程连接数据库防火墙在建立 ...

  5. 设计模式学习(二):面向对象设计原则与UML类图

    一.UML类图和面向对象设计原则简介 在学习设计模式之前,需要找我一些预备知识,主要包括UML类图和面向对象设计原则. UML类图可用于描述每一个设计模式的结构以及对模式实例进行说明,而模式结构又是设 ...

  6. SQL各种连接——自连接、内连接、外连接、交叉连接的使用

    首先准备了两个表 (Student 和 Course),其中 Student 表中的 C_S_Id 字段为外键列,关联的是 Course 表的 C_Id 主键列. 内连接(inner join):满足 ...

  7. iOS 开发,混合使用 ARC 和非ARC

    [前提知识] ARC:Automatic Reference Counting,自动引用计数 在开发 iOS 3 以及之前的版本的项目时我们要自己负责使用引用计数来管理内存,比如要手动 retain. ...

  8. Visual C++的DLL

    动态链接库 (DLL) 是作为共享函数库的可执行文件. 动态链接提供了一种方法,使进程可以调用不属于其可执行代码的函数. 函数的可执行代码位于一个 DLL 中,该 DLL 包含一个或多个已被编译.链接 ...

  9. 切换usb口的命令

    open:dd if=imx6dl-sabresd-usboc.dtb of=/dev/mmcblk0 bs=512 seek=1536 conv=fsyncclose:dd if=imx6dl-sa ...

  10. AVAudioSession(3):定制 Audio Session 的 Category

    本文转自:AVAudioSession(3):定制 Audio Session 的 Category | www.samirchen.com 本文内容主要来源于 Working with Catego ...