POJ 1385 Lifting the Stone (多边形的重心)
Lifting the Stone
题目链接:
http://acm.hust.edu.cn/vjudge/contest/130510#problem/G
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
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
```
Source
2016-HUST-线下组队赛-5
##题意:
求多边形的重心.
##题解:
裸到爆的求重心,开场就打了,硬是最后才过掉.
坑在四舍五入时出现了-0.00的情况导致WA... 涨姿势了,以后切记.
##代码:
``` cpp
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define maxn 1110000
#define LL long long
#define eps 1e-8
#define inf 0x3f3f3f3f
#define mod 1000000007
#define mid(a,b) ((a+b)>>1)
#define IN freopen("in.txt","r",stdin);
using namespace std;
int n;
struct pt{
double x,y;
}p[maxn];
double xmul(pt p0, pt p1, pt p2) {
return (p1.x-p0.x)(p2.y-p0.y) - (p2.x-p0.x)(p1.y-p0.y);
}
pt center(int n) {
pt ret = {0,0}, t;
double t1 = 0, t2;
for(int i=1; i<n-1; i++) {
t2 = xmul(p[i+1],p[0],p[i]);
t.x = (p[0].x + p[i].x + p[i+1].x) / 3.0;
t.y = (p[0].y + p[i].y + p[i+1].y) / 3.0;
ret.x += t.x * t2;
ret.y += t.y * t2;
t1 += t2;
}
ret.x /= t1, ret.y /= t1;
return ret;
}
int main()
{
//IN;
int T; cin >> T;
while(T--)
{
scanf("%d", &n);
for(int i=0; i<n; i++) {
scanf("%lf %lf", &p[i].x, &p[i].y);
}
pt ans = center(n);
if(ans.x > -0.005 && ans.x < 0.005) ans.x = 0.0;
if(ans.y > -0.005 && ans.y < 0.005) ans.y = 0.0;
printf("%.2f %.2f\n", ans.x, ans.y);
}
return 0;
}
POJ 1385 Lifting the Stone (多边形的重心)的更多相关文章
- [POJ 1385] Lifting the Stone (计算几何)
题目链接:http://poj.org/problem?id=1385 题目大意:给你一个多边形的点,求重心. 首先,三角形的重心: ( (x1+x2+x3)/3 , (y1+y2+y3)/3 ) 然 ...
- hdu 1115 Lifting the Stone 多边形的重心
Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- poj 1115 Lifting the Stone 计算多边形的中心
Lifting the Stone Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- Lifting the Stone(多边形重心)
Lifting the Stone Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- POJ1385 Lifting the Stone 多边形重心
POJ1385 给定n个顶点 顺序连成多边形 求重心 n<=1e+6 比较裸的重心问题 没有特别数据 由于答案保留两位小数四舍五入 需要+0.0005消除误差 #include<iostr ...
- 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: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- Lifting the Stone(hdu1115)多边形的重心
Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- hdu1115 Lifting the Stone(几何,求多边形重心模板题)
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:pid=1115">http://acm.hdu.edu.cn/showproblem.php ...
随机推荐
- rename批量修改文件名
批量改名: 如文件,批量修改,把hello去掉[root@localhost wang]# ll-rw-r--r-- 1 root root 0 5月 14 02:36 a.hello.txt-rw- ...
- axios入门使用
vue项目中axios的基本使用和简单封装 axios中文文档官网 http://www.axios-js.com/docs/ 一:不封装直接使用 npm install axios 在main.js ...
- [Web 前端] 027 jQuery 相关尺寸与事件绑定
1. 相关尺寸 1.1 获取元素相对于文档的偏移量 var pos = $('#small').offset(); console.log(pos.left, pos.top); 1.2 获取当前元素 ...
- MySQL-快速入门(8)存储过程、存储函数
1.存储过程 1>创建存储过程:create procedure create procedure sp_name ([in | out | inout] param_name type) [c ...
- 《剑指offer》面试题26 复杂链表的复制 Java版
(定义一个新的数据结构,每个节点除了具有普通链表的next域外,还有一个额外的引用指向任意节点.我们要对由该特殊数据结构形成的链表进行复制.) 我的方法:也就是克隆一个这种特殊链表,很快想到先不考虑原 ...
- 题解 CF1140D 【Minimum Triangulation】
题意:求将一个n边形分解成(n-2)个三边形花费的最小精力,其中花费的精力是所有三角形的三顶点编号乘积的和(其中编号是按照顶点的顺时针顺序编写的) 考虑1,x,y连了一个三角形,x,y,z连了一个三角 ...
- liunx驱动----信号量的实现
使用信号量必须包含 <asm/semaphore.h> 头文件.其中相关结构体 struct semaphore 可以通过以下几种方式来声明或者初始化. 1.void sema_in ...
- Java中静态变量和实例变量的区别
静态变量属于类的级别,而实例变量属于对象的级别. 主要区别有两点: 1,存放位置不同 类变量随着类的加载存在于方法区中,实例变量随着对象的对象的建立存在于堆内存中. 2,生命周期不同 类变量的生命周期 ...
- ambari 2.5.0源码编译安装
参考:https://www.ibm.com/developerworks/cn/opensource/os-cn-bigdata-ambari/index.html Ambari 是什么 Ambar ...
- nroff - 用 groff 模拟 nroff 命令
总览 (SYNOPSIS) nroff [ -h ] [ -i ] [ -mname ] [ -nnum ] [ -olist ] [ -rcn ] [ -Tname ] [ file... ] 描述 ...