我们需要把一块石头平稳的从地板上拿起来。石头的底面是多边形且各个部分的高度都一样,我们需要找出石头的重心。

input

测试案例  T;

每组第一行给出N,表示定点数。

接下来N行,每行连个数,表示坐标。定点按顺时针或逆时针给出。

output

  重心坐标。两个数中间一个空格,每个数保留两位小数。

思路

  把多变形分成N-2个三角形,求出重心,重心的质量。(其实是质心)

根据   x=Σ(xi*mi)/Σmi,有因为mi 正比于体积 正比于 面积。

所以利用叉乘求面积。

 #include"iostream"
#include"cstdio"
#include"cstring"
#include"algorithm"
using namespace std;
struct Point
{
double x,y;
};
double Triangle(Point p0,Point p1,Point p2)
{
double s;
s=p0.x*p1.y+p1.x*p2.y+p2.x*p0.y-p1.x*p0.y-p2.x*p1.y-p0.x*p2.y;
//因为有规律,可以记一下。正:x 0->2,y比x大一,负:x 1->2->0,y比x小一。
return s;
}
int main()
{
int i,j;
int T,N;
double x1,y1;
Point p0,p1,p2;
double x,y;
double area,area0;
scanf("%d",&T);
while(T--)
{
scanf("%d",&N);
scanf("%lf%lf",&p0.x,&p0.y);
scanf("%lf%lf",&p1.x,&p1.y);
x=0,y=0;
area=0;
for(i=2;i<N;i++)
{
scanf("%lf%lf",&p2.x,&p2.y);
x1=p0.x+p1.x+p2.x;
y1=p0.y+p1.y+p2.y;
area0=Triangle(p0,p1,p2);
area+=area0;
x+=x1*area0;
y+=y1*area0;
p1=p2;
}
printf("%.2lf %.2lf\n",x/area/3,y/area/3);
}
return 0;
}

Lifting the Stone的更多相关文章

  1. poj 1115 Lifting the Stone 计算多边形的中心

    Lifting the Stone Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  2. Lifting the Stone(hdoj1115)

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

  3. (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 ...

  4. Lifting the Stone(求多边形的重心—)

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

  5. hdu 1115 Lifting the Stone 多边形的重心

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

  6. Lifting the Stone(hdu1115)多边形的重心

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

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

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

  8. hdu 1115 Lifting the Stone (数学几何)

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

  9. Lifting the Stone(多边形重心)

    Lifting the Stone Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

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

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

随机推荐

  1. web前端开发分享-css,js入门篇(转)

    转自:http://www.cnblogs.com/jikey/p/3600308.html 关注前端这么多年,没有大的成就,就入门期间积累了不少技巧与心得,跟大家分享一下,不一定都适合每个人,毕竟人 ...

  2. leetcode—sqrt

    1.题目描述   Implement int sqrt(int x).   Compute and return the square root of x. 2.解法分析 很明显,用二分搜索可解,但是 ...

  3. 最大二位子数组和问题(homework-02)

    前面已经谈过最大一维子数组和问题,这里面扩展到二维. 一. 常规情况 一个矩形的数组,找到一个矩形的子数组有最大的元素和,求这个和. 1. 从朴素算法入手,枚举矩形数组的4个顶点,以此计算其数组和.同 ...

  4. POJ 3259 Wormholes(最短路,判断有没有负环回路)

    Wormholes Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 24249   Accepted: 8652 Descri ...

  5. 什么是USBMini接口

    USB的接口有四种.一种是大头,有A型和B型两种,其中A型最常见,就是我们用的最多的标准的USB接头:一种是小头的,也就是USB Mini,也有A型和B型两种,其中B型应用最多,主要应用于手机.MP4 ...

  6. BestCoder Round #71 (div.2) (hdu 5621)

    KK's Point Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  7. QString 与 QByteArray笔记

    程序中在于外设打交到是常常会用到读硬件显示到控件,或是读控件写到硬件的情况,操作的最多的是字节流,所以肯定会用到QString 和QByteArray,下面测试一些常用的转换: #include &l ...

  8. POJ 2828 Buy Tickets (线段树 or 树状数组+二分)

    题目链接:http://poj.org/problem?id=2828 题意就是给你n个人,然后每个人按顺序插队,问你最终的顺序是怎么样的. 反过来做就很容易了,从最后一个人开始推,最后一个人位置很容 ...

  9. myeclipse内存配置

    配置文件路径:D:\work\myeclipse\MyEclipse for Spring 10\myeclipseforspring.ini 替换以下内容即可 -vmargs-Xmx768m-XX: ...

  10. poj 3501 Escape from Enemy Territory 二分+bfs

    水题,不解释. #include<stdio.h> #include<math.h> #include<cstring> #include<algorithm ...