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. git常用命令常用场景

    在使用git之前,一直用的是svn版本管理:与svn最大不同的是,git有两个仓库,一个是本地仓库,一个是服务器上共享的仓库:本地仓库是每个开发者自己独有的,即使commit提交也只是提交到本地仓库: ...

  2. 转---写一个网页进度loading

    作者:jack_lo www.jianshu.com/p/4c93f5bd9861 如有好文章投稿,请点击 → 这里了解详情 loading随处可见,比如一个app经常会有下拉刷新,上拉加载的功能,在 ...

  3. vscode 学习笔记 —— 重构

    一.vscode 自带 1.提取变量 2.提取方法 上面都是通过选中文本后出现的小灯泡操作的: 3.全局替换(多个文件中的)某个变量 选中变量按 F2,输入完成后按回车 二.vscode 插件 js- ...

  4. Shell - 简明Shell入门02 - 变量(Variable)

    示例脚本及注释 #!/bin/bash v1=test-variable_123 # 全局变量 v2=12345 v3='This is a test!' # 赋值语句使用单引号或双引号可以包含空格 ...

  5. 插入排序(java)

    这星期java老师布置的作业就是实现几种常见的排序算法,由于数据结构学了丢得差不多了,今天晚上搞了一晚上才搞出来插入排序的三种算法. 首先说个与题目不搭的话,今天写

  6. asp.net core中遇到需要自定义数据包解密方法的时候

    最近将公司的项目用.netcore重写, 服务的http外部接口部分收发消息是DES加解密的, 那么在asp.net core mvc的action处理之前需要加入解密这个步骤. 我第一想到的是用fi ...

  7. Firefox火狐 浏览器接口调试工具 JSON 格式化

    作为一名“IT界”的淫才,还是主攻Web端的淫才,相信大家经常会联调各种接口! 如今APP猖狂的年代接口联调更为频繁,当然我们常用于Firefox火狐 浏览器,所以这里主要讲Firefox火狐 浏览器 ...

  8. spring 后处理器

    Bean后处理器 新建maven项目并添加spring依赖,目录结构如下 Axe public interface Axe { public String chop(); } Person publi ...

  9. 《第一本Docker书》

    Docker简介 Docker依赖写时复制(copy-on-write),使修改应用程序非常迅速. Docker推荐单个容器只运行一个应用或进程,鼓励面向服务的架构和微服务架构. Docker的核心组 ...

  10. Java总结:开发环境

    更多请查看在线文集:http://android.52fhy.com/java/index.html Java是由Sun Microsystems公司于1995年5月推出的Java面向对象程序设计语言 ...