题目链接

  1. /*
  2. Name:nyoj-3-多边形重心问题
  3. Copyright:
  4. Author:
  5. Date: 2018/4/26 21:25:41
  6. Description:
  7. ACM国际大学生程序设计竞赛 算法与实现的模板
  8. */
  9. #include <iostream>
  10. #include <cstdio>
  11. #include <cmath>
  12. #include <algorithm>
  13. using namespace std;
  14. const double eps = 1e-;
  15. int cmp(double x) {
  16. if (fabs(x) < eps) return ;
  17. if (x > )return ;
  18. return -;
  19. }
  20. //point
  21. struct point {
  22. double x, y;
  23. point (){}
  24. point (double a, double b):x(a), y(b) { }
  25. void input() {
  26. scanf("%lf %lf", &x, &y);
  27. }
  28. friend point operator - (const point &a, const point &b) {
  29. return point(a.x-b.x, a.y-b.y);
  30. }
  31. friend point operator + (const point &a, const point &b) {
  32. return point(a.x+b.x, a.y+b.y);
  33. }
  34. friend point operator * (const double &a, const point &b) {
  35. return point (a * b.x, a*b.y);
  36. }
  37. friend point operator / (const point &a, const double &b) {
  38. return point (a.x / b, a.y /b);
  39. }
  40. friend bool operator == (const point &a, const point &b) {
  41. return (cmp(a.x - b.x) == && cmp(a.y - b.y) == );
  42. }
  43. };
  44. double det(const point &a, const point &b) {
  45. return a.x * b.y - a.y * b.x;
  46. }
  47. //polygon
  48. const int MAXN = ;
  49. struct polygon {
  50. int n;
  51. point a[MAXN];
  52. polygon(){
  53. }
  54. double area() {
  55. double sum = ;
  56. a[n] = a[];
  57. for (int i=; i<n; i++) sum+=det(a[i+], a[i]);
  58. return sum/;
  59. }
  60. point MassCenter() {
  61. point ans = point(, );
  62. if (cmp(area()) == ) return ans;
  63. a[n] = a[];
  64. for (int i=; i<n; i++) ans = ans + det(a[i+], a[i]) * (a[i] + a[i+]) ;
  65. return ans / area()/;
  66. }
  67. };
  68. int main()
  69. {
  70. int n;
  71. cin>>n;
  72. while (n--) {
  73. int m;
  74. cin>>m;
  75. polygon pgon;
  76. pgon.n = m;
  77. for (int i=; i<m; i++) {
  78. cin>>pgon.a[i].x>>pgon.a[i].y;
  79. }
  80. point ans = pgon.MassCenter();
  81. printf("%.3f %.3f\n", pgon.area(), ans.x+ans.y);
  82. }
  83. return ;
  84. }

nyoj-3-多边形重心问题(求多边形面积和中心)的更多相关文章

  1. HDU 1115(求质量均匀分布的多边形重心 物理)

    题意是给一个 n 边形,给出沿逆时针方向分布的各顶点的坐标,求出 n 边形的重心. 求多边形重心的情况大致上有三种: 一.多边形的质量都分布在各顶点上,像是用轻杆连接成的多边形框,各顶点的坐标为Xi, ...

  2. UVALive 4426 Blast the Enemy! --求多边形重心

    题意:求一个不规则简单多边形的重心. 解法:多边形的重心就是所有三角形的重心对面积的加权平均数. 关于求多边形重心的文章: 求多边形重心 用叉积搞一搞就行了. 代码: #include <ios ...

  3. hdu_1115_Lifting the Stone(求多边形重心)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1115 题意:给你N个点围成的一个多边形,让你求这个多边形的重心. 题解: 将多边形划分为若干个三角形. ...

  4. Lifting the Stone(求多边形的重心—)

    Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...

  5. hdu 1115:Lifting the Stone(计算几何,求多边形重心。 过年好!)

    Lifting the Stone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  6. nyoj 3 多边形重心问题

    多边形重心问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:5   描述 在某个多边形上,取n个点,这n个点顺序给出,按照给出顺序将相邻的点用直线连接, (第一个和最后一个连接 ...

  7. 三角剖分求多边形面积的交 HDU3060

    //三角剖分求多边形面积的交 HDU3060 #include <iostream> #include <cstdio> #include <cstring> #i ...

  8. Area - POJ 1654(求多边形面积)

    题目大意:从原点开始,1-4分别代表,向右下走,向右走,向右上走,向下走,5代表回到原点,6-9代表,向上走,向左下走,向左走,向左上走.求出最后的多边形面积. 分析:这个多边形面积很明显是不规则的, ...

  9. hdu 2036 求多边形面积 (凸、凹多边形)

    <题目链接> Problem Description “ 改革春风吹满地,不会AC没关系;实在不行回老家,还有一亩三分地.谢谢!(乐队奏乐)” 话说部分学生心态极好,每天就知道游戏,这次考 ...

  10. hdu 2528:Area(计算几何,求线段与直线交点 + 求多边形面积)

    Area Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

随机推荐

  1. spring下配置shiro

    1.web.xml中加入shiro的过滤器: <!-- Spring --> <!-- 配置Spring配置文件路径 --> <context-param> < ...

  2. 深入理解MVC架构

    MVC MVC是一种设计模式(Design pattern),也就是一种解决问题的方法和思路, 是上世纪80年代提出的,到现在已经颇有历史了. MVC的意义在于指导开发者将数据与表现解耦,提高代码,特 ...

  3. python删除列表中所有的空元素

    while '' in list: list.remove('')

  4. SpringBoot整合集成redis

    Redis安装:https://www.cnblogs.com/zwcry/p/9505949.html 1.pom.xml <project xmlns="http://maven. ...

  5. MySQL-版本及服务介绍

    一.MySQL各版本 1.MySQL产品 下载地址:https://www.mysql.com/downloads/ Oracle MySQL Cloud Service(commercial) 商业 ...

  6. linux下安装jsp开发运行环境(centos7)

    1 开发环境包括 1)apache-tomcat 2)java-jdk 3)mysql 2 apache-tomcat安装(应该先装java再装tomcat) 1)到官网下载最新版本(不建议用yum安 ...

  7. WKWebview的基本使用

    在开发过程中,iOS 中实现加载 web 页面主要有两种控件,UIWebView 和 WKWebview,两种控件对应具体的实现方法不同.WKWebView是苹果公司在iOS8系统推出的,这里主要概述 ...

  8. hadoop mapreduce实现数据去重

    实现原理分析: map函数数将输入的文本按照行读取,   并将Key--每一行的内容   输出    value--空. reduce  会自动统计所有的key,我们让reduce输出key-> ...

  9. Codeforces Round #390 (Div. 2) A B C D

    这是一场比较难的div2 ... 比赛的时候只出了AB A很有意思 给出n个数 要求随意的把相邻的数合并成任意多数 最后没有为0的数 输出合并区间个数与区间 可以想到0可以合到任何数上并不改变该数的性 ...

  10. python练习_三级菜单

    python练习_三级菜单 需求: 做一个地区查询三级菜单,输入一级能够打印下一级 在第三级个第二级输入e可以返回上一级 在任意一级输入q则退出程序 以下代码实现的功能与思路: 功能: (1)通过In ...