hdu 1115 Lifting the Stone
题目链接:hdu 1115
计算几何求多边形的重心,弄清算法后就是裸题了,这儿有篇博客写得很不错的: 计算几何-多边形的重心
代码如下:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int N = ; struct point {
double x,y;
point() {}
point(double x, double y): x(x), y(y) {}
void read() { scanf("%lf %lf",&x,&y); }
void readint() {
int x,y;
scanf("%d %d",&x,&y);
this->x = x;
this->y = y;
}
point operator - (const point &p2) const {
return point(x - p2.x, y - p2.y);
}
} p[N]; typedef point Vector; double cross(Vector a, Vector b) {
return a.x * b.y - a.y * b.x;
} double Area(point a, point b, point c) {
return cross(b - a, c - a) / ;
} inline double center3(double a, double b, double c) {
return a + b + c;
} int main() {
int t,n;
scanf("%d",&t);
while(t--) {
scanf("%d",&n);
for(int i = ; i <= n; ++i)
p[i].read(); double up = , down = ;
point ans;
for(int i = ; i <= n - ; ++i) {
up += center3(p[].x, p[i].x, p[i + ].x) * Area(p[], p[i], p[i + ]);
down += Area(p[], p[i], p[i + ]);
}
ans.x = up / down / ; up = ; down = ;
for(int i = ; i <= n - ; ++i) {
up += center3(p[].y, p[i].y, p[i + ].y) * Area(p[], p[i], p[i + ]);
down += Area(p[], p[i], p[i + ]);
}
ans.y = up / down / ;
printf("%.2lf %.2lf\n", ans.x, ans.y);
}
return ;
}
有个要注意的小细节,对每个小三角形求重心时对最后结果 / 3 即可,而不必在中间过程 / 3,应该是精度问题,所以除法应尽可能避免,因为这题的 n 有点大,所以不断 / 3 操作损失的精度是很大的。
hdu 1115 Lifting the Stone的更多相关文章
- hdu 1115:Lifting the Stone(计算几何,求多边形重心。 过年好!)
Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- hdu 1115 Lifting the Stone 多边形的重心
Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- 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 ...
- Hdoj 1115.Lifting the Stone 题解
Problem Description There are many secret openings in the floor which are covered by a big heavy sto ...
- hdu1115 Lifting the Stone(几何,求多边形重心模板题)
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:pid=1115">http://acm.hdu.edu.cn/showproblem.php ...
- (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 ...
- Lifting the Stone(多边形重心)
Lifting the Stone Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- *HDU 1115 计算几何
Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
随机推荐
- [ios][opengles]OpenGL ES基础知识简介
参考: http://www.cnblogs.com/shangdahao/archive/2011/11/05/2233587.html 3D变换:模型,视图,投影与Viewport: http:/ ...
- [团队项目3.0]Scrum团队成立
Scrum团队成立 5.Scrum团队成立 5.1 团队名称,团队目标.团队口号.团队照: 5.2 角色分配 产品负责人: 决定开发内容和优先级排序,最大化产品以及开发团队工作的价值. Scrum M ...
- java实现贪吃蛇游戏
最简单的4个java类就可以实现贪吃蛇: main函数: package tcs; public class GreedSnake { public static void main(String[] ...
- Codeforces Round #336 Zuma
D. Zuma time limit per test: 2 seconds memory limit per test: 512 megabytes input: standard input ...
- Pupu(快速幂取模)
Pupu Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submissi ...
- 如何快捷输入函数上方的注释代码(Summary)
写完类或函数(注意必须写完,不然出现的信息会不完整)后,在其上方空行输入/**,然后回车,就可以为其添加Summary.
- COM技术の组件
什么是COM COM,Component Object Mode即组件对象模型.之所以称之为“模型”,是表明COM是一种编程规范(非具体代码),通过这种规范我们能够编写出语言无关的,可扩展的,内部变化 ...
- Json 入门例子(form表单)【0】
<script> $(function () { var aa = $("#fm").serialize().replace(/\+/g, ""); ...
- Xcode插件管理以及Xcode7 升级
一,Xcode插件管理工具 Alcatraz: mkdir -p ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins; cur ...
- 我的android学习经历27
前几天忙着学校的互联网+项目比赛,没有时间学习android和发一些东西,主要是这两天太累了,我是项目组长,好多东西去弄,今天已经交稿去进行初赛. 马上收拾收拾心情,继续我的andorid菜鸟之路 加 ...