nyoj-3-多边形重心问题(求多边形面积和中心)
/*
Name:nyoj-3-多边形重心问题
Copyright:
Author:
Date: 2018/4/26 21:25:41
Description:
ACM国际大学生程序设计竞赛 算法与实现的模板
*/
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const double eps = 1e-;
int cmp(double x) {
if (fabs(x) < eps) return ;
if (x > )return ;
return -;
}
//point
struct point {
double x, y;
point (){}
point (double a, double b):x(a), y(b) { }
void input() {
scanf("%lf %lf", &x, &y);
}
friend point operator - (const point &a, const point &b) {
return point(a.x-b.x, a.y-b.y);
}
friend point operator + (const point &a, const point &b) {
return point(a.x+b.x, a.y+b.y);
}
friend point operator * (const double &a, const point &b) {
return point (a * b.x, a*b.y);
}
friend point operator / (const point &a, const double &b) {
return point (a.x / b, a.y /b);
}
friend bool operator == (const point &a, const point &b) {
return (cmp(a.x - b.x) == && cmp(a.y - b.y) == );
}
};
double det(const point &a, const point &b) {
return a.x * b.y - a.y * b.x;
}
//polygon
const int MAXN = ;
struct polygon {
int n;
point a[MAXN];
polygon(){
}
double area() {
double sum = ;
a[n] = a[];
for (int i=; i<n; i++) sum+=det(a[i+], a[i]);
return sum/;
}
point MassCenter() {
point ans = point(, );
if (cmp(area()) == ) return ans;
a[n] = a[];
for (int i=; i<n; i++) ans = ans + det(a[i+], a[i]) * (a[i] + a[i+]) ;
return ans / area()/;
}
};
int main()
{
int n;
cin>>n;
while (n--) {
int m;
cin>>m;
polygon pgon;
pgon.n = m;
for (int i=; i<m; i++) {
cin>>pgon.a[i].x>>pgon.a[i].y;
}
point ans = pgon.MassCenter();
printf("%.3f %.3f\n", pgon.area(), ans.x+ans.y);
}
return ;
}
nyoj-3-多边形重心问题(求多边形面积和中心)的更多相关文章
- HDU 1115(求质量均匀分布的多边形重心 物理)
题意是给一个 n 边形,给出沿逆时针方向分布的各顶点的坐标,求出 n 边形的重心. 求多边形重心的情况大致上有三种: 一.多边形的质量都分布在各顶点上,像是用轻杆连接成的多边形框,各顶点的坐标为Xi, ...
- UVALive 4426 Blast the Enemy! --求多边形重心
题意:求一个不规则简单多边形的重心. 解法:多边形的重心就是所有三角形的重心对面积的加权平均数. 关于求多边形重心的文章: 求多边形重心 用叉积搞一搞就行了. 代码: #include <ios ...
- hdu_1115_Lifting the Stone(求多边形重心)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1115 题意:给你N个点围成的一个多边形,让你求这个多边形的重心. 题解: 将多边形划分为若干个三角形. ...
- Lifting the Stone(求多边形的重心—)
Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- hdu 1115:Lifting the Stone(计算几何,求多边形重心。 过年好!)
Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- nyoj 3 多边形重心问题
多边形重心问题 时间限制:3000 ms | 内存限制:65535 KB 难度:5 描述 在某个多边形上,取n个点,这n个点顺序给出,按照给出顺序将相邻的点用直线连接, (第一个和最后一个连接 ...
- 三角剖分求多边形面积的交 HDU3060
//三角剖分求多边形面积的交 HDU3060 #include <iostream> #include <cstdio> #include <cstring> #i ...
- Area - POJ 1654(求多边形面积)
题目大意:从原点开始,1-4分别代表,向右下走,向右走,向右上走,向下走,5代表回到原点,6-9代表,向上走,向左下走,向左走,向左上走.求出最后的多边形面积. 分析:这个多边形面积很明显是不规则的, ...
- hdu 2036 求多边形面积 (凸、凹多边形)
<题目链接> Problem Description “ 改革春风吹满地,不会AC没关系;实在不行回老家,还有一亩三分地.谢谢!(乐队奏乐)” 话说部分学生心态极好,每天就知道游戏,这次考 ...
- hdu 2528:Area(计算几何,求线段与直线交点 + 求多边形面积)
Area Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
随机推荐
- Django CSRF 原理分析
原文链接: https://blog.csdn.net/u011715678/article/details/48752873 参考链接:https://blog.csdn.net/clark_fit ...
- Android:日常学习笔记(9)———探究广播机制
Android:日常学习笔记(9)———探究广播机制 引入广播机制 Andorid广播机制 广播是任何应用均可接收的消息.系统将针对系统事件(例如:系统启动或设备开始充电时)传递各种广播.通过将 In ...
- CSS3 animation-iteration-count:infinite
原文:http://www.w3chtml.com/css3/properties/animation/animation-iteration-count.html animation-iterati ...
- $UML统一建模语言简介
(一)UML概述 1.面向对象软件开发的过程: (1)OOA(面向对象分析):建立分析模型并文档化. (2)OOD(面向对象设计):用面向对象思想对OOA的结果进行细化,得出设计模型. (3)OOP( ...
- Windows彻底卸载VMWare虚拟机
彻底卸载VMWare虚拟机 1.停止VMware相关服务 在服务中将VMware开头的所有服务停止 2.打开VMware安装向导 进入卸载页面 在卸载页面中选中VMware右键点击,进入更改后,页面为 ...
- 【leetcode刷题笔记】Wildcard Matching
Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single character. ...
- 【leetcode刷题笔记】Sudoku Solver
Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by th ...
- php数组函数-array_keys()
array_keys()函数返回包含数组中所有键名的一个新数组 如果提供了第二个参数,则返回键值为该值得键名 如果strict参数指定为true,则php会使用全等(===)来严格检查键值的 数据类型 ...
- Redux API之bindActionCreators
bindActionCreators(actionCreators,dispatch) 把 action creators 转成拥有同名 keys 的对象,但使用 dispatch 把每个 actio ...
- Windows10提示“没有权限使用网络资源”的解决方案
1.点击“开始→运行”,在“运行”对话框中输入“GPEDIT.MSC”,打开组策略编辑器 2.依次选择“计算机配置→Windows设置→安全设置→本地策略→用户权利分配” 3.双击“拒绝从网络访问这台 ...