Lifting the Stone

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

input

测试案例  T;

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

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

output

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

思路

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

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

所以利用叉乘求面积。

 1 #include"iostream"
 2 #include"cstdio"
 3 #include"cstring"
 4 #include"algorithm"
 5 using namespace std;
 6 struct Point
 7 {
 8     double x,y;
 9 };
10 double Triangle(Point p0,Point p1,Point p2)
11 {
12     double s;
13     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;
14     //因为有规律,可以记一下。正:x 0->2,y比x大一,负:x  1->2->0,y比x小一。
15     return s;
16 }
17 int main()
18 {
19     int i,j;
20     int T,N;
21     double x1,y1;
22     Point p0,p1,p2;
23     double x,y;
24     double area,area0;
25     scanf("%d",&T);
26     while(T--)
27     {
28         scanf("%d",&N);
29         scanf("%lf%lf",&p0.x,&p0.y);
30         scanf("%lf%lf",&p1.x,&p1.y);
31         x=0,y=0;
32         area=0;
33         for(i=2;i<N;i++)
34         {
35             scanf("%lf%lf",&p2.x,&p2.y);
36             x1=p0.x+p1.x+p2.x;
37             y1=p0.y+p1.y+p2.y;
38             area0=Triangle(p0,p1,p2);
39             area+=area0;
40             x+=x1*area0;
41             y+=y1*area0;
42             p1=p2;
43         }
44         printf("%.2lf  %.2lf\n",x/area/3,y/area/3);
45     }
46     return 0;
47 }

Lifting the Stone

时间: 2024-11-01 17:10:34

Lifting the Stone的相关文章

Lifting the Stone(hdoj1115)

Lifting the Stone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6104    Accepted Submission(s): 2546 Problem Description There are many secret openings in the floor which are covered by a big

HDU 1115 Lifting the Stone

Lifting the Stone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5440    Accepted Submission(s): 2278 Problem Description There are many secret openings in the floor which are covered by a big

Lifting the Stone(求任意多边形的重心)

Lifting the Stone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5432    Accepted Submission(s): 2273 Problem Description There are many secret openings in the floor which are covered by a big

hdu 1115 Lifting the Stone (数学几何)

Lifting the Stone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5203    Accepted Submission(s): 2155 Problem Description There are many secret openings in the floor which are covered by a big

HDOJ 1115 Lifting the Stone 多边形重心

来自:http://blog.csdn.net/tiaotiaoyly/article/details/2087498 1,质量集中在顶点上.n个顶点坐标为(xi,yi),质量为mi,则重心 X = ∑( xi×mi ) / ∑mi Y = ∑( yi×mi ) / ∑mi 特殊地,若每个点的质量相同,则 X = ∑xi  / n Y = ∑yi  / n 2,质量分布均匀.这个题就是这一类型,算法和上面的不同. 特殊地,质量均匀的三角形重心: X = ( x0 + x1 + x2 ) / 3

ACM-计算几何之Lifting the Stone——hdu1115

Lifting the Stone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5026    Accepted Submission(s): 2102 Problem Description There are many secret openings in the floor which are covered by a big

(hdu step 7.1.3)Lifting the Stone(求凸多边形的重心)

题目: Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 168 Accepted Submission(s): 98   Problem Description There are many secret openings in the floor which are covered by a big he

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

Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5370 Accepted Submission(s): 2239 Problem Description There are many secret openings in the floor which are covered by a big heavy

POJ1385 Lifting the Stone 多边形重心

POJ1385 给定n个顶点 顺序连成多边形 求重心 n<=1e+6 比较裸的重心问题 没有特别数据 由于答案保留两位小数四舍五入 需要+0.0005消除误差 #include<iostream> #include<stdio.h> #include<stdlib.h> #include<string.h> #include<math.h> #include<algorithm> #include<queue> #i