hdu 1115 Lifting the Stone【求多边形重心】
2015-12-02 22:24
423 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1115
代码:
代码:
#include <iostream> #include <set> #include <string> #include <cstdio> #include <string.h> #include <algorithm> #include <vector> using namespace std; double x0, y0, x1, y1, x2, y2; double s0, s1, s2; double x, y; int n; int main() { int t; scanf("%d",&t); while (t--) { scanf ("%d",&n); s0 = s1 = s2 = 0; cin >> x0 >> y0 >> x1 >> y1; for (int i = 2;i < n;i++) { cin >> x2 >> y2; x = (x0 + x1 + x2); y = (y0 + y1 + y2); double tmp = (x0*y1 + x1 * y2 + x2*y0 - x1*y0 - x2 * y1 - x0*y2); s0 += tmp; s1 += x*tmp; s2 += y*tmp; x1 = x2; y1 = y2; } //cout<<s0<<endl; if (s0 == 0) printf("0.00 0.00\n"); else printf("%.2lf %.2lf\n", s1 / s0 / 3, s2 / s0 / 3); } return 0; }
相关文章推荐
- 【Java基础】——HTML隐藏域
- JQuery的基本架构学习
- 《程序员面试宝典(第三版)》——欧立奇 / 刘洋 / 段韬
- python抓网页数据【ref:http://www.1point3acres.com/bbs/thread-83337-1-1.html】
- Redis集群明细文档(内容只说明了没有集群功能的redis)
- 执行数据库更新操作
- C_3:c语言的内存
- 《天才在左疯子在右》——高铭
- 事务——原子性、一致性、隔离性和持久性的理解
- Majority Element
- JFinal框架学习笔记二
- 对存取控制的认识
- Beta版本冲刺———第二天
- Servlet小总结(转)
- 编写一个程序从键盘输入字符,并按要求输出
- python显示中文
- android Camera
- asp连接sql server
- 我的第一个VTK程序--绘制球体
- struts2 集成webservice 的方法