Lifting the Stone(hdu1115)多边形的重心
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
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.
(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.
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.
#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)多边形的重心的更多相关文章
- POJ 1385 Lifting the Stone (多边形的重心)
Lifting the Stone 题目链接: http://acm.hust.edu.cn/vjudge/contest/130510#problem/G Description There are ...
- Lifting the Stone 计算几何 多边形求重心
Problem Description There are many secret openings in the floor which are covered by a big heavy sto ...
- poj 1115 Lifting the Stone 计算多边形的中心
Lifting the Stone Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- (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 ...
- hdu1115 Lifting the Stone(几何,求多边形重心模板题)
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:pid=1115">http://acm.hdu.edu.cn/showproblem.php ...
- Lifting the Stone(求多边形的重心—)
Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- hdu 1115:Lifting the Stone(计算几何,求多边形重心。 过年好!)
Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- Lifting the Stone(多边形重心)
Lifting the Stone Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- hdu 1115 Lifting the Stone 多边形的重心
Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
随机推荐
- 自用 docker-compose
version: '3.1' services: mysql: image: mysql: command: --default-authentication-plugin=mysql_native_ ...
- eclipse maven打war包
在eclipse中找到pom.xml文件右键 选择debug as 再选择Maven install运行后 按路径找到生成的war包 推荐https://www.cnblogs.com/qlqwjy/ ...
- 关于Java抽象类,接口与实现接口及派生类继承基类
1. 抽象类 抽象类就是有一个或多个方法只被声明而未被实现. 抽象方法的声明以分号结束,并且用关键字abstract来说明它以标识它为抽象方法. 格式: public abstract class 类 ...
- postgresql-hdd,ssd,效率
既有ssd又有hdd是将数据存储到ssd还是将索引存储到ssd的效率更高呢? 一种说法是索引是随机扫描,将索引放入ssd效率会增高, 一种说法是将数据放入ssd效率更高 最好的情况是将数据和索引都 ...
- Python中Flask框架SQLALCHEMY_ECHO设置
在用配置类的方式给app设置配置时, SQLALCHEMY_ECHO 这个是记录打印SQL语句用于调试的, 一般设置为False, 不然会在控制台输出一大堆的东西 /home/python/.virt ...
- OS之内存管理 --- 虚拟内存管理(一)
虚拟内存的背景 在基本的内存管理策略中,所有的策略的相同点都是:每个进程在执行之前需要完全处于内存中.那有没有一种方法可以不需要将进程所有页面加载到内存中就可以开始运行进程呢?有没有可能在进程需要某些 ...
- [转]Express框架
http://javascript.ruanyifeng.com/nodejs/express.html
- odoo开发笔记--自定义server action页面跳转注意
场景描述: 在添加自定义服务器动作 “复制全部”后发现直接创建了新的记录,并且直接进入到form保存完的状态. 如何解决: if yourself_obj_copy: return { 'type': ...
- Bash算术运算
使用let命令 let let let let let let let 使用expr命令 - ` # + ` # \* ` # / ` # / ` # − \* ` # +` # + -*· # -* ...
- Hadoop(三)搭建Hadoop全分布式集群
原文地址:http://www.cnblogs.com/zhangyinhua/p/7652686.html 阅读目录(Content) 一.搭建Hadoop全分布式集群前提 1.1.网络 1.2.安 ...