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 ...
随机推荐
- 【javascript】原生js更改css样式的两种方式
下面我给大家介绍的是原生js更改CSS样式的两种方式: 1通过在javascript代码中的node.style.cssText="css表达式1:css表达式2:css表达式3 &quo ...
- IE浏览器兼容性模式
最近支持公司的一个内部业务管理系统,系统是基于jQuery来实现:用了2年的MVVM框架的我转向这个完全使用jQuery框架来开发的系统,真是相当不爽(相信用过MVVM框架的跟我是相同的感受):更为憋 ...
- 【BZOJ1052】 [HAOI2007]覆盖问题
BZOJ1052 [HAOI2007]覆盖问题 前言 小清新思维题. 最近肯定需要一些思维题挽救我这种碰到题目只会模板的菜鸡. 这题腾空出世? Solution 考虑一下我们二分答案怎么做? 首先转换 ...
- 2019/4/23 todolist
近期的任务单子大概是这样吧 bjoi2019改完,写题解 hnoi2019改一些,写题解 找3道网络流写写 写一场agc,写题解 找2道简单计算几何写写
- [NOIP2018]赛道修建(二分+multiset)
考场上打了一个 \(vector\) 解法,因为我当时不会 \(multiset\) 好吧,我来讲一讲今年的 \(tgD1T3\) 首先,这题 \(55\) 分是不难想的 1. \(b_i=a_i+1 ...
- 重拾 BFC、IFC、GFC、FFC
温故知新,巩固基础 从 FC 开始 FC,Formatting Context,格式化上下文,是 W3C CSS2.1 规范中的一个概念,定义的是页面中一块渲染区域,并且有一套渲染规则,它决定了其子元 ...
- GPS轨迹数据可视化的三种途径
有一阵子没写过博客了,最近因为自己小队申请了项目有并且要帮研究生做一些数据处理的小任务,接触到可视化.这里介绍最近学到的了三种方法. 第一种是用python. 这里原理是用matplotlib里面的s ...
- ASP.NET 上传大文件(原创)
问题描述 需要在网站中上传文件,但是当文件大小太大的时候IIS会拒绝连接,导致用户看到不友好的错误界面. 解决方法 1.服务器端处理 在globle.asax中的protected void Appl ...
- 10 Tips for Optimizing Your Website’s Speed
转自:http://sixrevisions.com/web-development/site-speed-performance/ Web page speed and performance is ...
- Python全局解释器锁 -- GIL
首先强调背景: 1.GIL是什么?GIL的全称是Global Interpreter Lock(全局解释器锁),来源是python设计之初的考虑,为了数据安全所做的决定. 2.每个CPU在同一时间只能 ...