POJ1385 Lifting the Stone
Input
Output
Sample Input
2
4
5 0
0 5
-5 0
0 -5
4
1 1
11 1
11 11
1 11
Sample Output
0.00 0.00
6.00 6.00
数学 几何 求多边形的重心
三角形的重心是三个点坐标的平均值。
对于n边形,可以将其剖分成n-2个三角形,求每个三角形的重心,并以三角形面积为权重,求出各重心坐标的加权平均值,就是多边形的重心
/*by SilverN*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
struct point{
double x,y;
point operator - (point rhs){return (point){x-rhs.x,y-rhs.y};}
point operator + (point rhs){return (point){x+rhs.x,y+rhs.y};}
}p[mxn];
double Cross(point a,point b){return a.x*b.y-a.y*b.x;}
int n;
double smm;
double SX,SY;
int main(){
int i,j;
int T=read();
while(T--){
smm=SX=SY=;
n=read();
for(i=;i<=n;i++){
p[i].x=read();p[i].y=read();
}
// p[n+1]=p[1];
for(i=;i<n;i++){
double tmp=Cross(p[i]-p[],p[i+]-p[]);
SX+=(p[].x+p[i+].x+p[i].x)*tmp;
SY+=(p[].y+p[i+].y+p[i].y)*tmp;
smm+=tmp;
}
printf("%.2f %.2f\n",SX/smm/,SY/smm/);
}
return ;
}
POJ1385 Lifting the Stone的更多相关文章
- POJ1385 Lifting the Stone 多边形重心
POJ1385 给定n个顶点 顺序连成多边形 求重心 n<=1e+6 比较裸的重心问题 没有特别数据 由于答案保留两位小数四舍五入 需要+0.0005消除误差 #include<iostr ...
- poj 1115 Lifting the Stone 计算多边形的中心
Lifting the Stone Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- 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 ...
- hdu 1115:Lifting the Stone(计算几何,求多边形重心。 过年好!)
Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- hdu 1115 Lifting the Stone (数学几何)
Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
随机推荐
- c++异常处理--创建自己的异常处理类
复习了一下c++中的异常处理! 继承exception类 class myException : public std::exception { public: explicit myExceptio ...
- nginx安装php环境
1.php下载地址 https://secure.php.net/downloads.php(此次安装版本为7.0.33) 2.安装依赖的包 yum -y install libxml2 yum -y ...
- Ubuntu samba 安装与配置 实现windows和虚拟机中的Ubuntu共享文件
2. 安装sumba服务 sudo apt-get install samba samba-common 这里出现了小问题, Ubuntu上安装samba不能安装的问题,“下列的软件包有不能满足 ...
- GoF23种设计模式之创建型模式之工厂方法模式
一.概述 定义一个用于创建对象的接口,让子类去决定实例化哪个类.工厂方法将一个类的实例化延迟至其子类. 二.适用性 1.当一个类不知道它所必须创建的对象的类的时候. 2.当一个类希望由其子类来指定它所 ...
- 记忆化搜索:POJ1088-滑雪(经典的记忆化搜索)
skiing 时间限制:3000 ms | 内存限制:65535 KB 难度:5 描述 Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑 ...
- DFS:POJ1190-生日蛋糕(基础搜索)
生日蛋糕 Time Limit: 1000MS Memory Limit: 10000K 描述 7月17日是Mr.W的生日,ACM-THU为此要制作一个体积为Nπ的M层生日蛋糕,每层都是一个圆柱体. ...
- 【Directory】文件操作(初识文件操作二)
上篇我们说了关于文件的创建删除更改可以通过File这个类来完成.对于目录的操作其实File类也可以完成创建删除等相关的操作.用法跟文件的方法大致相同. 那么下面就一起来看一下关于目录相关的用法. 一, ...
- 1 - JVM随笔分类(java虚拟机的内存区域分配(一个不断记录和推翻以及再记录的一个过程))
java虚拟机的内存区域分配 在JVM运行时,类加载器ClassLoader在加载到类的字节码后,交由jvm的执行引擎处理, 执行过程中需要空间来存储数据(类似于Cpu及主存),此时的这段空间的分 ...
- python正则表达式应用优化实例
1.问题出现 需要提取一份xml文件中参数名和参数值,格式如下: <p name="actOlLaPdcch">true</p> 我们需要的字段如上,红色部 ...
- LeetCode661图片平滑器
题目描述:包含整数的二维矩阵 M 表示一个图片的灰度.你需要设计一个平滑器来让每一个单元的灰度成为平均灰度 (向下舍入) ,平均灰度的计算是周围的8个单元和它本身的值求平均,如果周围的单元格不足八个, ...