hdu1115【多边形求重心模板】
1.质量集中在顶点上。n个顶点坐标为(xi,yi),质量为mi,则重心(∑( xi×mi ) / ∑mi, ∑( yi×mi ) / ∑mi)
2.质量分布均匀。这个题就是这一类型,算法和上面的不同。
特殊地,质量均匀的三角形重心:(( x0 + x1 + x2 ) / 3,Y = ( y0 + y1 + y2 ) / 3)
以(0,0)为顶点三角剖分之后求三角形重心,把重心连起来转换成质量集中在顶点上的情况求解即可
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
const int N=1000005;
int T,n;
double am;
struct dian
{
double x,y,v;
dian(double X=0,double Y=0)
{
x=X,y=Y;
}
dian operator + (const dian &a) const
{
return dian(x+a.x,y+a.y);
}
dian operator - (const dian &a) const
{
return dian(x-a.x,y-a.y);
}
dian operator * (const double &a) const
{
return dian(x*a,y*a);
}
dian operator / (const double &a) const
{
return dian(x/a,y/a);
}
}p[N],a;
int read()
{
int r=0,f=1;
char p=getchar();
while(p>'9'||p<'0')
{
if(p=='-')
f=-1;
p=getchar();
}
while(p>='0'&&p<='9')
{
r=r*10+p-48;
p=getchar();
}
return r*f;
}
double cj(dian a,dian b)
{
return a.x*b.y-a.y*b.x;
}
int main()
{
T=read();
while(T--)
{
n=read();am=0,a.x=0,a.y=0;
for(int i=1;i<=n;i++)
p[i].x=read(),p[i].y=read();
p[n+1]=p[1];
for(int i=2;i<=n+1;i++)
{
double mj=cj(p[i-1],p[i]);
am+=mj,a=a+(p[i-1]+p[i])*mj;
}
printf("%.2f %.2f\n",a.x/am/3,a.y/am/3);
}
return 0;
}
hdu1115【多边形求重心模板】的更多相关文章
- Lifting the Stone(hdu1115)多边形的重心
Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- 多边形求重心 HDU1115
http://acm.hdu.edu.cn/showproblem.php?pid=1115 引用博客:https://blog.csdn.net/ysc504/article/details/881 ...
- hdu-1115 计算几何 求重心 凸多边形 面积
思想是分割成三角形,然后求三角形的重心.那么多边形重心就是若干个三角形的重心带权求中心,可以用质点质心公式. #include <cstdio> #include <iostream ...
- Lifting the Stone 计算几何 多边形求重心
Problem Description There are many secret openings in the floor which are covered by a big heavy sto ...
- hdu1115 Lifting the Stone(几何,求多边形重心模板题)
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:pid=1115">http://acm.hdu.edu.cn/showproblem.php ...
- HDU1115&&POJ1385Lifting the Stone(求多边形的重心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1115# 大意:给你个n,有n个点,然后给你n个点的坐标,求这n个点形成的多边形的重心的坐标. 直接套模 ...
- hdu1115(计算多边形几何重心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1115 题意:给出一些点,求这些点围成的多边形的重心: 思路: 方法1:直接分别求所有点的x坐标的平均值 ...
- Lifting the Stone(求多边形的重心—)
Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- POJ 1385 Lifting the Stone (多边形的重心)
Lifting the Stone 题目链接: http://acm.hust.edu.cn/vjudge/contest/130510#problem/G Description There are ...
随机推荐
- 123. Best Time to Buy and Sell Stock III ~~
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- ***iOS学习之Table View的简单使用和DEMO示例(共Plain普通+Grouped分组两种)
Table View简单描述: 在iPhone和其他iOS的很多程序中都会看到Table View的出现,除了一般的表格资料展示之外,设置的属性资料往往也用到Table View,Table View ...
- 2018 百度之星 初赛 第六题 HDU6349
三原色图 Accepts: 281 Submissions: 1261 Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 262144/ ...
- java学习——关于搜索异常处理的总结
根据网上的资料可以知道,异常处理是为了检测到程序运行中发生的非正常情况的检测而设立的一种机制,异常的英文单词是exception,字面翻译就是“意外.例外”的意思,也就是非正常情况.关于平常我们经常遇 ...
- 洛谷 P2862 [USACO06JAN]把牛Corral the Cows
P2862 [USACO06JAN]把牛Corral the Cows 题目描述 Farmer John wishes to build a corral for his cows. Being fi ...
- js如何获取一个object的第一个数据
var obj = { "1":"123", "2":"456" } console.info( obj[Object. ...
- Windows下SVN服务器及客户端的使用
原文地址:windows下配置VisualSVN Server服务器 作者:Deem_passion 下载安装文件: 服务端安装文件:VisualSVN-Server-1.6.2 客户端安装文件:To ...
- Win7查看本地是否安装JDK及安装路径的方法
工具/原料 win7 方法/步骤 1 开始->点击运行,输入:cmd 2 然后在命令提示符中,输入:java -version 假如看到有版本提示那么安装成功 3 假如忘记了java ...
- WebLogic中"域"的概念
WebLogic 版权声明:本文为博主原创文章,未经博主允许不得转载. WebLogic Server中的域是逻辑上相关的一组 WebLogic Server 资源,可以作为一个单元进行管理.一个域中 ...
- centos、mac的grafana安装和简单使用
1.安装: 参考官方文档安装说明:https://grafana.com/grafana/download Redhat & Centos(64 Bit): wget https://s3-u ...