Lifting the Stone

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7674    Accepted Submission(s): 3252

Problem 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
 
Source
 
题意:
计算多边形的重心。
代码:

  

 //1.  质量集中在顶点上
// n个顶点坐标为(xi,yi),质量为mi,则重心
//  X = ∑( xi×mi ) / ∑mi
//  Y = ∑( yi×mi ) / ∑mi
//  特殊地,若每个点的质量相同,则
//  X = ∑xi / n
//  Y = ∑yi / n
//2. 质量分布均匀
//  特殊地,质量均匀的三角形重心:
//  X = ( x0 + x1 + x2 ) / 3
//  Y = ( y0 + y1 + y2 ) / 3
//3. 三角形面积公式:S = ( (x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1) ) / 2 ; 向量p2p1与向量p3p1叉积/2。
//因此做题步骤:1、将多边形分割成n-2个三角形,根据3公式求每个三角形面积。 //用向量面积 凹多边形时面积会在多边形外面。
// 2、根据2求每个三角形重心。
// 3、根据1求得多边形重心。 //当总面积是0的情况时注意后面除总面积。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
struct nod
{
double x,y;
};
double getarea(nod p0,nod p1,nod p2)
{
return ((p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x))/;
}
int main()
{
int t,n;
nod p0,p1,p2;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
scanf("%lf%lf",&p0.x,&p0.y);
scanf("%lf%lf",&p1.x,&p1.y);
double sumarea=,sumx=,sumy=;
for(int i=;i<=n;i++)
{
scanf("%lf%lf",&p2.x,&p2.y);
double Area=getarea(p0,p1,p2);
sumarea+=Area;
sumx+=(p0.x+p1.x+p2.x)*Area/;
sumy+=(p0.y+p1.y+p2.y)*Area/;
p1=p2;
}
printf("%.2lf %.2lf\n",sumx/sumarea,sumy/sumarea);
}
return ;
}

*HDU 1115 计算几何的更多相关文章

  1. hdu 1115 Lifting the Stone

    题目链接:hdu 1115 计算几何求多边形的重心,弄清算法后就是裸题了,这儿有篇博客写得很不错的: 计算几何-多边形的重心 代码如下: #include<cstdio> #include ...

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

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

  3. hdu 2108:Shape of HDU(计算几何,判断多边形是否是凸多边形,水题)

    Shape of HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  4. HDU 2202 计算几何

    最大三角形 Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  5. *HDU 2108 计算几何

    Shape of HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  6. HDU 5784 (计算几何)

    Problem How Many Triangles (HDU 5784) 题目大意 给定平面上的n个点(n<2000),询问可以组成多少个锐角三角形. 解题分析 直接统计锐角三角形较困难,考虑 ...

  7. hdu 4720 计算几何简单题

    昨天用vim练了一道大水题,今天特地找了道稍难一点的题.不过也不是很难,简单的计算几何而已.练习用vim编码,用gdb调试,结果居然1A了,没调试...囧... 做法很简单,无非就是两种情况:①三个巫 ...

  8. HDU 6205[计算几何,JAVA]

    题目链接[http://acm.hdu.edu.cn/showproblem.php?pid=6206] 题意: 给出不共线的三个点,和一个点(x,y),然后判断(x,y)在不在这三个点组成的圆外. ...

  9. hdu 3320 计算几何(三维图形几何变换)

    openGL Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Subm ...

随机推荐

  1. 宏定义#define的用法

    预处理#define定义函数 #include <stdio.h> #define Connect(x,y) x##y //"##"表示连接x与y int main(v ...

  2. POJ 2533 Longest Ordered Subsequence LCS O(n*log(n))

    题目链接 最长上升子序列O(n*log(n))的做法,只能用于求长度不能求序列. #include <iostream> #define SIZE 1001 using namespace ...

  3. xcode 8 重新支持插件

    苹果出了Xcode8之后,就加了签名让之前的自定义插件无法继续的安装使用.想要重新使用插件的话只要用自己的签名覆盖苹果的签名即可. 1.创建自签名证书 钥匙串->钥匙串访问->证书助理-& ...

  4. HTML5 的一些小的整理吧

    主要的就是一些HTML 5 API 的使用 也是借鉴别人的博客 ,和MDN(中文部分的还是能看的懂) 上面的一些东西 具体的代码在 有道云笔记里面也有. 先把总得列出来 1.Canvas绘图 学完这个 ...

  5. freemarker IllegalAccessError 错误

    java.lang.IllegalAccessError: tried to access method freemarker.ext.servlet.AllHttpScopesHashModel.& ...

  6. 网站开启https后加密协议始终是TLS1.0如何配置成TLS1.2?

    p { margin-bottom: 0.1in; line-height: 120% } 网站开启https后加密协议始终是TLS1.0如何配置成TLS1.2? 要在服务器上开启 TLSv1.,通常 ...

  7. 关闭电脑SSD的磁盘碎片整理

    小白往往会把机械硬盘时代的习惯带进固态硬盘时代,比如碎片整理.机械硬盘时代砖家最喜欢告诉小白:“系统慢了吧?赶紧碎片整理撒.”小白屁颠屁颠地整理去了.殊不知碎片整理对于SSD来说完全就是种折磨.这种“ ...

  8. Python,ElementTree模块处理XML时注释无法读取和保存的问题

    from xml.etree import ElementTree class CommentedTreeBuilder ( ElementTree.XMLTreeBuilder ): def __i ...

  9. ssh反向连接和简单实现

    转自:http://blog.chinaunix.net/uid-20109107-id-2954579.html SSH反向连接的使用 1.什么是反向连接?反向连接是指主机A(受控端)主动连接主机B ...

  10. maven权威指南学习笔记(二)——安装、运行、获取帮助

    这部分在网上很容易找到详细教程,这里就略写了. 基础:系统有配置好的jdk,通过 命令行 java -version,有类似下面的提示,表示java环境以配好 下载maven:官网 http://ma ...