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 ...
随机推荐
- [团队项目]----Math Calculator
团队项目 ----Math Calculator 任务: 1.每个团队从Github上fork这个项目的源代码 https://github.com/RABITBABY/We-have-bing 2. ...
- Ramsey theorem in Combinarotics
- 【算法】简单动态规划——三逆数的O(N^2)解法!
问题描述: 三逆数定义:给一个数的序列A[0,1,....N-1]),当i<j<k且A[i]>A[j]>A[k]时,称作ai,aj,ak为一个三逆数. 现在给定一个长度为N的数 ...
- JAVA基础知识之IO——Java IO体系及常用类
Java IO体系 个人觉得可以用"字节流操作类和字符流操作类组成了Java IO体系"来高度概括Java IO体系. 借用几张网络图片来说明(图片来自 http://blog.c ...
- 大型网站技术架构介绍--squid
一.大型网站技术架构介绍 1.pv高 ip高 并发量 2.大型网站架构重点 1. 高性能:响应时间,TPS,系统性能计数器.缓存,消息队列等. 高可用性High Availabilit ...
- Mysql-学习笔记(==》权限管理 十 三)
-- 用户与权限管理-- 查看当前服务器上的所有账号密码主机SELECT USER,PASSWORD,HOST FROM mysql.user; -- 设置账号密码SET PASSWORD=PASSW ...
- 窗体移动API
//窗体移动API [DllImport("user32.dll")] public static extern bool ReleaseCapture(); [DllImport ...
- 位运算(bit)
位运算(bit) Time Limit:2000ms Memory Limit:64MB [题目描述] lyk最近在研究位运算.它发现除了xor,or,and外还有很多运算.它新定义了一种运算符“ ...
- php 日期时间操作-可算出几天后的时间
本文为大家介绍一下根据PHP时间戳获取当前时期的具体方式.strtotime能将任何英文文本的日期时间描述解析为Unix时间戳,我们结合mktime()或date()格式化日期时间获取指定的时间戳,实 ...
- mvcAPI (入门 3)(源码)
mvcAPI (入门 3)(源码) http://download.csdn.net/detail/chunfang740/9078579