Lifting the Stone(多边形重心)
Lifting the Stone
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
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 //求多边形的重心
第一行是案例数,然后是点的个数,然后是每个点的坐标
重量均匀分布的三角形,重心 X = (x1 + x2 + x3)/3 , Y = ( y1 + y2 + y3 )/3
质量集中在顶点上的多边形,n 个顶点坐标为(xi,yi),质量为mi,则重心
X = ∑( xi×mi ) / ∑mi
Y = ∑( yi×mi ) / ∑mi
思路 : 将这个多边形转换成多个三角形,然后求出各个重心,将这些重心连起来形成个新多边形,求出重心
所以套公式就行了
#include <iostream>
#include <cstdio>
using namespace std; struct Node
{
double x,y;
}node[]; int main()
{
int n;
cin>>n;
while (n--)
{
int dian;
cin>>dian;
double x1,x2,y1,y2;
cin>>x1>>y1>>x2>>y2; int i;
double x,y;
double sumarea=0.0,sumx=0.0,sumy=0.0;
for (i=;i<dian;i++)
{
cin>>x>>y;
double s=( (x2-x1) * (y-y1) - (x-x1) * (y2-y1) ) / ;
// s= ( (x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1) ) / 2
sumarea+=s;
sumx+=s*(x1+x2+x)/;
sumy+=s*(y1+y2+y)/;
x2=x;
y2=y;
}
printf("%.2lf %.2lf\n",sumx/sumarea,sumy/sumarea);
}
return ;
}
Lifting the Stone(多边形重心)的更多相关文章
- POJ1385 Lifting the Stone 多边形重心
POJ1385 给定n个顶点 顺序连成多边形 求重心 n<=1e+6 比较裸的重心问题 没有特别数据 由于答案保留两位小数四舍五入 需要+0.0005消除误差 #include<iostr ...
- 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(求多边形的重心—)
Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- 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 ...
- hdu1115 Lifting the Stone(几何,求多边形重心模板题)
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:pid=1115">http://acm.hdu.edu.cn/showproblem.php ...
- 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 ...
- (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 ...
随机推荐
- How to Clear setInterval() without Knowing the ID
ProblemDeclaring a setInterval() without keeping a reference to it (which is returned from the funct ...
- 在MyEclipse上安装GIT插件EGit
MyEclipse2016 CI 下载地址:http://pan.baidu.com/s/1gfBw9Ab 1.“Help”->"Install from Site" 2.在 ...
- 倍福TwinCAT(贝福Beckhoff)基础教程2.2 TwinCAT常见类型使用和转换_结构体
在DUTs文件夹上右击添加结构体,结构体中可以放基本变量类型,也可以嵌套其他结构体 使用的时候,需要声明结构体的实例,然后按照类.属性的格式来读写变量,会有代码的自动提示 你也可以声明数组,类 ...
- sqlmap tamper绕过安全狗
可以过5.3版本 放出py #!/usr/bin/env python """ Copyright (c) 2006-2014 sqlmap developers (ht ...
- 四种异步更新UI的方法
Android要求只能在UI线程中更新UI,要想在其他线程中更新UI,大致有四种方式: 1.使用Handler消息传递机制(推荐)2.使用AsyncTask异步任务(推荐)3.使用runOnUiThr ...
- ionic准备之angular基础——run方法(4)
可以看到整个angular.module对象具有以下各种属性和方法 <!DOCTYPE html> <html lang="en"> <head> ...
- 运用JS导出ecxel表格、实现文件重命名
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- 已知有字符串foo=”get-element-by-id”,写一个function将其转化成驼峰表示法”getElementById”
题目:已知有字符串foo=”get-element-by-id”,写一个function将其转化成驼峰表示法”getElementById”. 代码: <!DOCTYPE html> &l ...
- STL学习笔记(序列式容器)
Vector Vector是一个动态数组. 1.Vector的操作函数 构造.拷贝和析构 vector<Elem> c //产生一个空vector ,其中没有任何元素 vector< ...
- 【BIEE】01_下载安装BIEE(Business Intelligence)11g 11.1.1.9.0
环境准备 安装文件 如果操作系统是64位,则下载64位版本,我安装的系统是64位的 1.下载所有安装文件 1.1 Oracle Database 11g R2 下载地址: http://www.ora ...