- 题目描述: http://poj.org/problem?id=1012
- 题目分析: 该题就是给定多边形n 个顶点, 求重心
//IDE:vc6.0 #include <iostream> using namespace std; struct point { double x, y; }; double xmult(point p1,point p2,point p0){ return (p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y); } point barycenter(int n, point* p) { point ret; double area = 0.0, t; ret.x = ret.y = 0.0; for(int i = 1; i < n - 1; i++) { t = xmult(p[i], p[i+1], p[0]) / 2.0; area += t; ret.x += (p[0].x + p[i].x + p[i+1].x) * t; ret.y += (p[0].y + p[i].y + p[i+1].y) * t; } ret.x /= (3 * area); ret.y /= (3 * area); return ret; } int main() { //freopen("in.txt", "r", stdin); point* p, ret; int ncases, n; //ncases 个测试用例, n 个点 scanf("%d", &ncases); while(ncases--) { scanf("%d", &n); p = new point[n]; for(int i = 0; i < n; i++) scanf("%lf %lf", &p[i].x, &p[i].y); ret = barycenter(n, p); printf("%.2lf %.2lf\n", ret.x, ret.y); delete []p; } return 0; }
参考自:http://blog.csdn.net/zxy_snow/archive/2011/05/03/6386832.aspx
发表评论
-
ACM 之 Java BigInteger
2011-06-01 20:26 0Java 的大整数类在ACM 中大有用武之地 ... -
判断点是否构成多边形, 顶点连续给出
2011-05-26 14:27 0#include <cstdio> #inc ... -
poj pku 1981 Circle and Points 点与圆 位置关系
2011-05-26 11:29 1261题目描述: http://poj.org/problem?id ... -
poj 1032 Parliament 数学
2011-05-25 17:34 1211题目描述: http://poj.org/problem?i ... -
poj 2676 Sudoku dfs 深搜
2011-05-16 21:05 872题目描述: http://poj.org/problem?i ... -
hdoj 2064 汉诺塔III 递推
2011-05-15 22:29 883题目描述: http://acm.hdu.edu.cn/sh ... -
hdoj 1207 汉诺塔II dp 动态规划
2011-05-15 21:22 1667题目描述: http://acm.hdu.edu.cn/sh ... -
poj 2506 Tiling 递推
2011-05-15 11:18 906题目描述: http://poj.org/problem?i ... -
poj 2420 A Star not a Tree? 多边形 费马点
2011-05-14 18:57 1796题目描述: http://poj.org/problem?i ... -
poj 2954 Triangle Pick 定理
2011-05-14 16:36 1083题目描述: http://poj.org/problem?i ... -
poj 1012 Joseph
2011-05-10 17:42 1231题目描述:poj.org/problem?id=10 ... -
zoj 1081 Points Within 点与多边形关系
2011-05-07 17:51 1132题目描述: http://acm.zju.edu.cn/on ... -
poj 1835 宇航员
2011-05-03 17:00 799题目描述:http://poj.org/problem?id ... -
poj 2398 Toy Storage
2011-04-23 20:19 714题目描述:http://www.poj.org/proble ... -
poj 1654 Area 多边形面积
2011-04-23 20:10 895题目描述:http://poj.org/proble ... -
poj 2318 TOYS 点 直线 位置关系
2011-04-23 10:06 664题目描述:http://poj.org/problem?id= ... -
poj pku 1673 EXOCENTER OF A TRIANGLE 三角形 垂心
2011-04-09 16:41 542题目描述:http://poj.org/problem?id= ... -
pc 111303 uva 10195 The Knights Of The Round Table
2011-04-04 16:06 750题目描述:http://www.programming-cha ... -
pc 111302 uva 10180 Rope Crisis in Ropeland!
2011-04-03 20:46 837题目描述: http://www.programming-ch ... -
poj 1971 Parallelogram Counting 平行四边形个数
2011-04-03 10:05 1213题目描述:http://poj.org/problem?id= ...
相关推荐
北大POJ1426-Find The Multiple【BFS+同余模】 解题报告+AC代码
北大POJ1027-The Same Game 解题报告+AC代码
北大POJ1163-The Triangle 解题报告+AC代码
北大POJ1163-The Triangle
POJ2635-The Embarrassed Cryptographer 测试数据。 来源:NCPC 2005 问题D
北大POJ3267-The Cow Lexicon
北大POJ2635-The Embarrassed Cryptographer 解题报告+AC代码
北大POJ2965-The Pilots Brothers' refrigerator 解题报告+AC代码
北大POJ3982-The Fibonacci sequence 解题报告+AC代码
北大POJ3267-The Cow Lexicon 解题报告+AC代码
poj 1611 The Suspects 代码 并查集的应用
poj 3548 Restoring the digits.md
poj 3554 Almost the shortest route.md
北大POJ1207-The 3n + 1 problem 解题报告+AC代码
北大POJ2151-Check the difficulty of problems 解题报告+AC代码
POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类
北大POJ2983-Is the Information Reliable【差分约束+优化Bellman】 解题报告+AC代码
北大POJ3239-Solution to the n Queens Puzzle 解题报告+AC代码
poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题...
北大POJ2388-Who's in the Middle 解题报告+AC代码