题意:求一个不规则简单多边形的重心。

解法:多边形的重心就是所有三角形的重心对面积的加权平均数.

关于求多边形重心的文章: 求多边形重心

用叉积搞一搞就行了。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#define Mod 1000000007
#define eps 1e-8
using namespace std; struct Point{
double x,y;
Point(double x=, double y=):x(x),y(y) {}
void input() { scanf("%lf%lf",&x,&y); }
};
typedef Point Vector;
int dcmp(double x) {
if(x < -eps) return -;
if(x > eps) return ;
return ;
}
Vector operator + (Vector A, Vector B) { return Vector(A.x + B.x, A.y + B.y); }
Vector operator - (Vector A, Vector B) { return Vector(A.x - B.x, A.y - B.y); }
Vector operator * (Vector A, double p) { return Vector(A.x*p, A.y*p); }
Vector operator / (Vector A, double p) { return Vector(A.x/p, A.y/p); }
double Cross(Vector A, Vector B) { return A.x*B.y - A.y*B.x; } double CalcConvexArea(Point* p,int n) { //凸包面积
double area = 0.0;
for(int i=;i<n-;i++)
area += Cross(p[i]-p[],p[i+]-p[]);
return area*0.5;
}
Point p[],ch[]; int main()
{
int n,i,j,cs = ;
while(scanf("%d",&n)!=EOF && n)
{
for(i=;i<n;i++) p[i].input();
double S = CalcConvexArea(p,n);
double X = 0.0, Y = 0.0;
for(i=;i<n;i++) {
double area = 0.5*Cross(p[i-]-p[],p[i]-p[]);
X += area*(p[].x+p[i-].x+p[i].x)/3.0;
Y += area*(p[].y+p[i-].y+p[i].y)/3.0;
}
printf("Stage #%d: %.6f %.6f\n",cs++,X/S,Y/S);
}
return ;
}

UVALive 4426 Blast the Enemy! --求多边形重心的更多相关文章

  1. UVALive 4426 Blast the Enemy! 计算几何求重心

    D - Blast the Enemy! Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Subm ...

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

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

  3. hdu1115 Lifting the Stone(几何,求多边形重心模板题)

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:pid=1115">http://acm.hdu.edu.cn/showproblem.php ...

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

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

  5. poj3855Blast the Enemy!(多边形重心)

    链接 #include <iostream> #include<cstdio> #include<cstring> #include<algorithm> ...

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

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

  7. HDOJ(1115)多边形重心

    Lifting the Stone http://acm.hdu.edu.cn/showproblem.php?pid=1115 题目描述:输入n个顶点(整数),求它们围成的多边形的重心. 算法:以一 ...

  8. hdu 1115(计算多边形重心)

    题意:已知一多边形没有边相交,质量分布均匀.顺序给出多边形的顶点坐标,求其重心. 分析: 求多边形重心的题目大致有这么几种: 1,质量集中在顶点上.n个顶点坐标为(xi,yi),质量为mi,则重心 X ...

  9. hdu 1115(多边形重心问题)

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

随机推荐

  1. Collection框架

    Collection框架 集合框架(Collection Framework)泛指java.util包的若干个类和接口.如Collection,List,ArrayList,LinkedList,Ve ...

  2. HTML5标签与HTML4标签的区别示例介绍_html5教程技巧

    (1)概念的变化: HTML5专注内容与结构,而不专注的表现 <header> <hgroup>导航相关数据</hgroup> </header> &l ...

  3. ADO.NET 中的新增功能

    ADO.NET 中的新增功能: .NET Framework (current version) 以下是 .NET Framework 4.5 中 ADO.NET 的新增功能. SqlClient D ...

  4. Web 前端开发精华文章集锦(jQuery、HTML5、CSS3)【系列十七】

    <Web 前端开发精华文章推荐>2013年第五期(总第十七期)和大家见面了.梦想天空博客关注 前端开发 技术,分享各种增强网站用户体验的 jQuery 插件,展示前沿的 HTML5 和 C ...

  5. if语句,case语句

    1.句式:if...then.判断赋值 例: if RadioButton1.Checked then sex:='男' else if RadioButton2.Checked then sex:= ...

  6. [python]数据整理,将取得的众多的沪深龙虎榜数据整一整

    将昨日取得的众多的沪深龙虎榜数据整一整 提取文件夹内所有抓取下来的沪深龙虎榜数据,整理出沪深两市(含中小创)涨幅榜股票及前5大买入卖出资金净值,保存到csv文件 再手动使用数据透视表进行统计 原始数据 ...

  7. SuperMap iServer Ubuntu 开机自启动脚本

    在/etc/init.d/文件夹里面设置相关的文件 1.为了保证创建文件的读写权限与默认一致,我们只需要cp一个默认的启动文件即可 2.删除iserver里面的所有信息 提示:直接执行“:1,$d” ...

  8. UIBezierPath-绘制基本图形

    步骤1:确定路径 步骤2:渲染 override func draw(_ rect: CGRect) { let path:UIBezierPath // 矩形 // path = UIBezierP ...

  9. iOS--手势之谜

    原文转至: http://www.cnblogs.com/huangjianwu/p/4675648.html iOS在手机APP的手势操作中包含了:拖动.捏合.旋转.点按.长按.轻扫.自定义等等,详 ...

  10. Android 四大组件之再论service

    service常见的有2种方式,本地service以及remote service. 这2种的生命周期,同activity的通信方式等,都不相同. 关于这2种service如何使用,这里不做介绍,只是 ...