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 ...
随机推荐
- spring下配置shiro
1.web.xml中加入shiro的过滤器: <!-- Spring --> <!-- 配置Spring配置文件路径 --> <context-param> < ...
- 深入理解MVC架构
MVC MVC是一种设计模式(Design pattern),也就是一种解决问题的方法和思路, 是上世纪80年代提出的,到现在已经颇有历史了. MVC的意义在于指导开发者将数据与表现解耦,提高代码,特 ...
- python删除列表中所有的空元素
while '' in list: list.remove('')
- SpringBoot整合集成redis
Redis安装:https://www.cnblogs.com/zwcry/p/9505949.html 1.pom.xml <project xmlns="http://maven. ...
- MySQL-版本及服务介绍
一.MySQL各版本 1.MySQL产品 下载地址:https://www.mysql.com/downloads/ Oracle MySQL Cloud Service(commercial) 商业 ...
- linux下安装jsp开发运行环境(centos7)
1 开发环境包括 1)apache-tomcat 2)java-jdk 3)mysql 2 apache-tomcat安装(应该先装java再装tomcat) 1)到官网下载最新版本(不建议用yum安 ...
- WKWebview的基本使用
在开发过程中,iOS 中实现加载 web 页面主要有两种控件,UIWebView 和 WKWebview,两种控件对应具体的实现方法不同.WKWebView是苹果公司在iOS8系统推出的,这里主要概述 ...
- hadoop mapreduce实现数据去重
实现原理分析: map函数数将输入的文本按照行读取, 并将Key--每一行的内容 输出 value--空. reduce 会自动统计所有的key,我们让reduce输出key-> ...
- Codeforces Round #390 (Div. 2) A B C D
这是一场比较难的div2 ... 比赛的时候只出了AB A很有意思 给出n个数 要求随意的把相邻的数合并成任意多数 最后没有为0的数 输出合并区间个数与区间 可以想到0可以合到任何数上并不改变该数的性 ...
- python练习_三级菜单
python练习_三级菜单 需求: 做一个地区查询三级菜单,输入一级能够打印下一级 在第三级个第二级输入e可以返回上一级 在任意一级输入q则退出程序 以下代码实现的功能与思路: 功能: (1)通过In ...