Lifting the Stone

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Description

There are many secret openings in the floor which are covered by a big heavy stone. When the stone is lifted up, a special mechanism detects this and activates poisoned arrows that are shot near the opening. The only possibility is to lift the stone very slowly and carefully. The ACM team must connect a rope to the stone and then lift it using a pulley. Moreover, the stone must be lifted all at once; no side can rise before another. So it is very important to find the centre of gravity and connect the rope exactly to that point. The stone has a polygonal shape and its height is the same throughout the whole polygonal area. Your task is to find the centre of gravity for the given polygon. 

Input

The input consists of T test cases. The number of them (T) is given on the first line of the input file. Each test case begins with a line containing a single integer N (3 <= N <= 1000000) indicating the number of points that form the polygon. This is followed by N lines, each containing two integers Xi and Yi (|Xi|, |Yi| <= 20000). These numbers are the coordinates of the i-th point. When we connect the points in the given order, we get a polygon. You may assume that the edges never touch each other (except the neighboring ones) and that they never cross. The area of the polygon is never zero, i.e. it cannot collapse into a single line. 

Output

Print exactly one line for each test case. The line should contain exactly two numbers separated by one space. These numbers are the coordinates of the centre of gravity. Round the coordinates to the nearest number with exactly two digits after the decimal point (0.005 rounds up to 0.01). Note that the centre of gravity may be outside the polygon, if its shape is not convex. If there is such a case in the input data, print the centre anyway. 

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(多边形重心)的更多相关文章

  1. POJ1385 Lifting the Stone 多边形重心

    POJ1385 给定n个顶点 顺序连成多边形 求重心 n<=1e+6 比较裸的重心问题 没有特别数据 由于答案保留两位小数四舍五入 需要+0.0005消除误差 #include<iostr ...

  2. hdu 1115 Lifting the Stone 多边形的重心

    Lifting the Stone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  3. Lifting the Stone(求多边形的重心—)

    Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...

  4. Lifting the Stone(hdu1115)多边形的重心

    Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...

  5. hdu 1115:Lifting the Stone(计算几何,求多边形重心。 过年好!)

    Lifting the Stone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  6. hdu1115 Lifting the Stone(几何,求多边形重心模板题)

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:pid=1115">http://acm.hdu.edu.cn/showproblem.php ...

  7. POJ 1385 Lifting the Stone (多边形的重心)

    Lifting the Stone 题目链接: http://acm.hust.edu.cn/vjudge/contest/130510#problem/G Description There are ...

  8. poj 1115 Lifting the Stone 计算多边形的中心

    Lifting the Stone Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  9. (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 ...

随机推荐

  1. Hadoop之HDFS详解

    1.HDFS的概念和特性 它是一个文件系统,其次是分布式的 重要特性: 1).HDFS中的文件在物理上是分块存储(block),新版默认128M 2).客户端通过路径来访问文件,形如:hdfs://n ...

  2. Jquery.data()的值存放再什么地方的问题?

    Where is jQuery.data() stored? Where does jQuery store the values of the data() that it sets to DOM ...

  3. Nodejs扩展,实现消息弹窗

    參考https://github.com/olalonde/node-notify的实现 模块的C++代码 node_gtknotify.cc #include <v8.h> #inclu ...

  4. WEB接口测试之Jmeter接口测试自动化 (三)(数据驱动测试) 接口测试与数据驱动

    转载:http://www.cnblogs.com/chengtch/p/6576117.html 1简介 数据驱动测试,即是分离测试逻辑与测试数据,通过如excel表格的形式来保存测试数据,用测试脚 ...

  5. python——内置对象

    python的内置对象 对象类型 常量示例/用法 Number(数字) 3.14159, 1234, 999L 3+4j String(字符串) 'spam', "guido's" ...

  6. java统计中英文字数 Java问题通用解决代码

    http://yangchao20020.blog.163.com/blog/static/483822472011111635424751/   这个不适用于新浪微博字数的统计,结果有差别,若需要可 ...

  7. 中小企业 DevOps 从 0 到 1

    原文:http://www.sohu.com/a/145065274_262549 今天主要有四个课题: 先聊一聊 DevOps: 然后跟大家聊一聊运维知识的体系和职业发展: 再是中小企业基于开源的 ...

  8. java数字签名算法之RSA

    © 版权声明:本文为博主原创文章,转载请注明出处 实例 1.项目结构 2.pom.xml <project xmlns="http://maven.apache.org/POM/4.0 ...

  9. 微信公众号开发之创建菜单栏代码示例(php)

    思路很简单:就是先获取access_token,然后带着一定规则的json数据参数请求创建菜单的接口.废话不多讲,直接上代码. class Wechat { public $APPID="w ...

  10. 浅谈BloomFilter【上】基本概念和实现原理

        在日常生活中.包括在设计计算机软件时,我们常常要推断一个元素是否在一个集合中.     比方在字处理软件中,须要检查一个英语单词是否拼写正确(也就是要推断 它是否在已知的字典中).在 FBI. ...