Lifting the Stone

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

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
 
 
题意:求多边形的重心,,,,
 
模版题。
#include<stdio.h>
#include<stdlib.h>
/*==================================================*\
| 求多边形重心
| INIT: pnt[]已按顺时针(或逆时针)排好序;
| CALL: res = bcenter(pnt, n);
\*==================================================*/
struct point
{
double x, y;
}pnt[],res;
point bcenter(point pnt[], int n)//重心
{
point p, s;
double tp, area = , tpx = , tpy = ;
p.x = pnt[].x;
p.y = pnt[].y;
for (int i = ; i <= n; ++i)
{
// point: 0 ~ n-1
s.x = pnt[(i == n) ? : i].x;
s.y = pnt[(i == n) ? : i].y;
tp = (p.x * s.y - s.x * p.y);//叉乘
area += tp / ;
tpx += (p.x + s.x) * tp;
tpy += (p.y + s.y) * tp;
p.x = s.x;
p.y = s.y;
}
s.x = tpx / ( * area);
s.y = tpy / ( * area);
return s;
}
int main()
{
int T,N,i;
scanf("%d",&T);
while(T--)
{
scanf("%d",&N);
for(i=;i<N;i++)
{
scanf("%lf%lf",&pnt[i].x,&pnt[i].y);
}
res=bcenter(pnt, N);
printf("%0.2lf %0.2lf\n",res.x,res.y);
}
return ;
}
 

Lifting the Stone(hdu1115)多边形的重心的更多相关文章

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

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

  2. Lifting the Stone 计算几何 多边形求重心

    Problem Description There are many secret openings in the floor which are covered by a big heavy sto ...

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

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

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

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

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

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

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

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

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

  8. Lifting the Stone(多边形重心)

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

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

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

随机推荐

  1. 01_python_初始python

    一.初始python python是一门解释型语言,弱类型语言 / python解释器最为常用的是cpython(官方) 弱类型语言:   a = 1 a = 'alex'   #说明变量a既可以是整 ...

  2. " XSS易容术---bypass之编码混淆篇+辅助脚本编写"

    一.前言本文原创作者:vk,本文属i春秋原创奖励计划,未经许可禁止转载!很多人对于XSS的了解不深.一提起来就是:“哦,弹窗的”.”哦,偷cookie的.”骚年,你根本不知道什么是力量.虽然我也不知道 ...

  3. ES6之Array.from()方法

    Array.from()方法就是将一个类数组对象或者可遍历对象转换成一个真正的数组. 那么什么是类数组对象呢?所谓类数组对象,最基本的要求就是具有length属性的对象. 1.将类数组对象转换为真正数 ...

  4. centos7下elasticSearch安装配置

    OS:Centos7x虚拟机 1H2Gjdk:1.8elasticsearch:5.6.0 1.下载“elasticsearch-5.6.0.tar.gz”解压到/usr/local/elastics ...

  5. Docker三剑客之Docker Machine

    一.什么是Docker Machine Docker Machine 是Docker官方编排项目之一,使用go语言编写的,使用不同引擎在多种平台上快速的安装Docker环境,开源地址:https:// ...

  6. MVC3学习:将excel文件导入到sql server数据库

    思路: 1.将excel文件导入到服务器中. 2.读取excel文件,转换成dataset. 3.循环将dataset数据插入到数据库中. 本例子使用的表格为一个友情链接表F_Link(LinkId, ...

  7. 网络Socket编程UDP协议例子

    服务端代码 public class UDPChatServer { //通讯端口 private Integer port=8000; //数据报文的通讯通道对象 private DatagramC ...

  8. C# 多线程学习系列二

    一.关于前台线程和后台线程 1.简介 CLR中线程分为两种类型,一种是前台线程.另一种是后台线程. 前台线程:应用程序的主线程.Thread构造的线程都默认为前台线程 后台线程:线程池线程都为后台线程 ...

  9. linux下安装lnmp环境

    安装nginx   1 检查是否安装该程序: which nginx           #查看nginx是否存在 which php             #查看php是否存在 which mys ...

  10. js便签笔记(5)——Dean Edwards大牛的跨浏览器AddEvent()设计(不知道是不是jQuery事件系统的原型)

    1. 前言: 在看Aaron的jquery源码解读时候,看到事件系统那块,作者提到了Dean Edwards的添加事件的设计,于是就点进去看了看.首先让我吃惊的是,代码非常少,寥寥几十行,非常简单.于 ...