【计算几何初步:多边形中心】【HDU1115】Lifting the Stone
一.质点系重心公式
x=(x1*m1+x2*m2+x3*m3.....xn*mn)/M (M=m1+m2+m3+m4...+mn)
二.三角形重心
可直接求得,但在多边形剖分中 各三角形的质点的质量大小不一样 质量大小等于三角形面积.
三.多边形重心
三角形剖分+任意点的三角形剖分+三角形重心+质点系重心公式+任意点的三角形剖分
所以很容易知道一种很优美的计算公式(看代码)
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#define oo 0x13131313
#define maxn 1000000+10
using namespace std;
struct point{
double x,y;
};
point A[maxn];
int N;
double ansX,ansY;
double Sarea;
void input()
{
ansX=0;ansY=0;Sarea=0;
cin>>N;
for(int i=1;i<=N;i++)
{
scanf("%lf%lf",&A[i].x,&A[i].y);
}
}
void init()
{
freopen("a.in","r",stdin);
freopen("a.out","W",stdout);
}
void get_Sarea()
{
for(int i=1;i<=N;i++)
{
int j=i+1;
if(j==N+1) j=1;
Sarea+=(A[i].x*A[j].y-A[j].x*A[i].y)*0.5;
}
}
void get_ansXansY()
{
for(int i=1;i<=N;i++)
{
int j=i+1;
if(j==N+1) j=1;
double area=(A[i].x*A[j].y-A[j].x*A[i].y)*0.5;
ansX+=area*(A[i].x+A[j].x); // area*(A[i].x+A[j].x+0)/3 质点的重量
ansY+=area*(A[i].y+A[j].y);
}
ansX=ansX/(3*Sarea);
ansY=ansY/(3*Sarea);
}
int main()
{
int T;
cin>>T;
while(T--)
{
input();
get_Sarea();
get_ansXansY();
printf("%.2lf %.2lf\n",ansX,ansY);
}
return 0;
}
【计算几何初步:多边形中心】【HDU1115】Lifting the Stone的更多相关文章
- hdu1115 Lifting the Stone(几何,求多边形重心模板题)
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:pid=1115">http://acm.hdu.edu.cn/showproblem.php ...
- hdu 1115:Lifting the Stone(计算几何,求多边形重心。 过年好!)
Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- poj 1115 Lifting the Stone 计算多边形的中心
Lifting the Stone Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- Lifting the Stone(hdu1115)多边形的重心
Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- Lifting the Stone(求多边形的重心—)
Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- Lifting the Stone(多边形重心)
Lifting the Stone Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- POJ 1385 Lifting the Stone (多边形的重心)
Lifting the Stone 题目链接: http://acm.hust.edu.cn/vjudge/contest/130510#problem/G Description There are ...
- hdu 1115 Lifting the Stone 多边形的重心
Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- Lifting the Stone(hdoj1115)
Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- (hdu step 7.1.3)Lifting the Stone(求凸多边形的重心)
题目: Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
随机推荐
- css-网页整体css布局
<!DOCTYPE html><!--有限宽度带居中布局:<style>*{margin:0;padding:0;list-style:none;} .zong{back ...
- 高逼格的实现WiFi共享,不安装第三方wifi共享软件,两种方式实现开启wifi的功能
作为一枚程序员,不会点高逼格的doc命令,那么都有点感觉对不起自己的行业了,好了废话就到这里了 第一种方式: 首先使用cmd命令:window键+R 然后输入cmd回车 第一种方式: 第一步: 设 ...
- Android Activity和intent
- PHP学习笔记三十三【自定义错误处理器】
<?php //自定义错误处理器 //$errorno 错误号 //$errmes错误信息 //这两个参数是必须的 function my_error($errorno,$errmes) { e ...
- mono for android工具下载
http://www.wuleba.com/25510.html Windows平台:http://xamarin.com/installer_assets/v3/Windows/Universal/ ...
- web跳转到自己的app
做个笔记 原文:http://blog.csdn.net/ba_jie/article/details/6884818 iPhone SDK可以把你的App和一个自定义的URL Scheme绑定.该U ...
- hdu1064Financial Management
Problem Description Larry graduated this year and finally has a job. He’s making a lot of money, but ...
- android设置图片变化的四种效果代码
activity代码如下: package com.example.chapter12_graphic_animation; import android.os.Bundle; import andr ...
- (转) C/C++中结构体(struct)知识点强化
本文转载于 http://pcedu.pconline.com.cn/empolder/gj/c/0503/567942_all.html#content_page_1 所有程序经过本人验证,部分程序 ...
- poj2774 Long Long Message(后缀数组or后缀自动机)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Long Long Message Time Limit: 4000MS Me ...