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. 文件流:"fopen","fclose",“ftell”"fseek","fgets","fprintf" ,“feof”,"fwrite","fread"

    char const* filename="D:/hello.txt"; 路径名使用的是“/”或者使用 转义字符“\\”: "fopen", FILE *fp= ...

  2. 直方图均衡(HE)与局部色调映射(LTM) .

    直方图均衡(Histogram Equalization)是图像处理中一个十分基础的概念,具有调整图像灰度,增强对比度的作用.    限制对比度自适应直方图均衡(Contrast Limited Ad ...

  3. Solr 6.6.0 ERROR: Port 8983 is already being used by another process.

    在目录D:\work\Solr\solr-6.6.0\bin下打开命令框: 输入:solr -e dih报错:ERROR: Port 8983 is already being used by ano ...

  4. Node.js 网页瘸腿稍强点爬虫再体验

    这回爬虫走得好点了,每次正常读取文章数目总是一样的,但是有程序僵住了情况,不知什么原因. 代码如下: // 内置http模块,提供了http服务器和客户端功能 var http=require(&qu ...

  5. 【VAB】获取库文件地址

    如何获取Excle库文件地址呢?具体代码如下: Public Sub 获取Excel库文件夹的路径() MsgBox "库文件夹的路径是: " & Application. ...

  6. 正则表达式Pattern ,Matcher

    正则表达式:符合一定规则的表达式 作用:用于专门操作字符串 特点:用于一些特定的符号来表示一些代码的操作,这样就简化代码的书写 学习正则表达式就是要学习一些特殊符号的使用 好处:简化对字符串复杂的操作 ...

  7. javascript中keyCode与charCode属性

    好记性不如烂笔头啊,最近总是忘记这两个属性的区别.想了想,从别人博客上转一遍过来吧,时常看下 键盘事件拥有两个属性,keyCode和CharCode,他们之间有一些不一样之处.keyCode表示用户按 ...

  8. 第九节: 利用RemoteScheduler实现Sheduler的远程控制 第八节: Quartz.Net五大构件之SimpleThreadPool及其四种配置方案 第六节: 六类Calander处理六种不同的时间场景 第五节: Quartz.Net五大构件之Trigger的四大触发类 第三节: Quartz.Net五大构件之Scheduler(创建、封装、基本方法等)和Job(创建、关联

    第九节: 利用RemoteScheduler实现Sheduler的远程控制   一. RemoteScheduler远程控制 1. 背景: 在A服务器上部署了一个Scheduler,我们想在B服务器上 ...

  9. 安装Reshaper后Intellisense失效

    安装Reshaper后Intellisense失效或希望用vs2017的Intellisense功能 安装完毕后,IDE 的智能提示(Intellisense)便会默认使用 Resharper 的提示 ...

  10. $.ajax 温故而知新坑

    $.ajax的配置项中使用 contentType: "application/json" 时,Data选项允许为String类型,如JSON.stringify({abc:123 ...