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. 探究Entity Framework如何在多个仓储层实例之间工作单元的实现及原理(2018-05-31修改部分严重错误代码)

    前言 1.本文的前提条件:EF上下文是线程唯一,EF版本6.1.3. 2.网上已有相关API的详细介绍,本文更多的是作为我自己的个人学习研究记录. 3.2018-05-31修改DbSession.cs ...

  2. Could not find installable ISAM

    程序中去读EXCEL文档,以前一直参考<Asp.net读取Excel文件 2>http://www.cnblogs.com/insus/archive/2011/05/05/2037808 ...

  3. JVM活学活用——GC算法 垃圾收集器

    概述 垃圾收集 Garbage Collection 通常被称为“GC”,它诞生于1960年 MIT 的 Lisp 语言,经过半个多世纪,目前已经十分成熟了. jvm 中,程序计数器.虚拟机栈.本地方 ...

  4. Flask系列08--Flask中flask_session, redis插件

    一.安装 1.flask_session 不想将Session的信息存放在Cookie 将Session存放在Redis Cookie中保存Session的ID flask中的session是直接将数 ...

  5. ubuntu14中把openssh升级到7.5

    经验证可用 下载相关tar.gz包,没有下载到的,可以在这里下载.http://download.csdn.net/download/songanshu/10023663 apt install -y ...

  6. go generate命令有啥作用呢?

    go generate命令其实就是用来生成代码用的,一般情况下需要配置其他工具和库一起使用 go官网有个实例: painkiller.go package painkiller type Pill i ...

  7. 【sping揭秘】13、Spring AOP一世&二世

    Spring AOP一世 Spring AOP中的advice Before advice 这个就是在方法执行之前执行,也就是在对应的joinpoint之前 spring AOP二世 开启aspect ...

  8. POJ 2603

    #include<iostream> #include<stdio.h> #define M 350000 #define N 30000 using namespace st ...

  9. 生成代码的代码 之 POJO生成器 之二 模板实现

    在之前的一篇博客中,我们写了利用node.js来生成JAVA的POJO代码的方法.有评论说可以利用模板来做这件事.当时认为模板只能做简单的字符串替换,所以可能无法完成任务.但是,仔细的学习了一个模板 ...

  10. Python动态变量名定义与调用

    动态变量名赋值 在使用tkinter时需要动态生成变量,如动态生成var1...var10变量 使用exec动态赋值 exec在python3中是内置函数,它支持python代码的动态执行. 示例: ...