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 ...
随机推荐
- hdu1875kruskal简单应用。
标记是dificulty 2,水,开始kruskal时练手题,只需开始时数据处理下,不符合要求的边不要,要理解并查集和Kruskal,就简单了,判断下是否联通图,(只需在记加入有效边时候统计连通分支数 ...
- [Bzoj1069][Scoi2007]最大土地面积(凸包)(旋转卡壳)
1069: [SCOI2007]最大土地面积 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 3629 Solved: 1432[Submit][Sta ...
- Java子类重写父类方法注意问题收集(转)
子类不能重写父类的静态方法,私有方法.即使你看到子类中存在貌似是重写的父类的静态方法或者私有方法,编译是没有问题的,但那其实是你重新又定义的方法,不是重写.具体有关重写父类方法的规则如下: 重写规则之 ...
- Java时间戳转化为今天、昨天、明天(字符串格式)
原文:http://www.open-open.com/code/view/1435301895825 时间戳,相信大家一定都不陌生,服务器经常会传回来时间戳,需要我们对时间戳进行处理.各种麻烦不断, ...
- [LeetCode][Java] Roman to Integer
题目: Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from ...
- 使用PowerShell 创建SharePoint 站点
使用PowerShell 创建SharePoint 站点 在SharePoint开发中,你应该学会使用PowerShell管理SharePoint网站.SharePoint Manag ...
- Django框架之路由
1,路由系统就是url系统,整个url系统就是请求进入Django项目的入口,每一个请求的种类由url分析完毕并再去返回相应的响应,它的本质是url与要为该url调用的视图函数之间的映射关系表(当项目 ...
- 不同linux版本下内核/系统/软件的安装及查询
(一)先介绍下使用apt-get 和使用yum 包管理工具的不同用法: 1.先看yum(redhat) yum的配置文件是/etc/yum.conf 更新:yum update 安装:yum inst ...
- GET 与 POST 的理解
1 HTTP请求 超文本传输协议(HTTP)的设计目的是保证客户机与服务器之间的通信. HTTP 的工作方式是客户机与服务器之间的请求-应答协议. 比如,客户端(浏览器) ...
- qrcode.react和jquery.qrcode生成二维码
qrcode.react 1.安装 npm install qrcode.react 2.用法(这里用的ant design) import React from 'react'; import QR ...