hdoj1115 Lifting the Stone
来源:互联网 发布:php里面怎么写html 编辑:程序博客网 时间:2024/05/16 06:08
Lifting the Stone
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 3 Accepted Submission(s) : 1
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
There are many secret openings in the floor which are covered by a big heavy stone. When the stone is lifted up, a special mechanism detects this and activates poisoned arrows that are shot near the opening. The only possibility is to lift the stone very slowly and carefully. The ACM team must connect a rope to the stone and then lift it using a pulley. Moreover, the stone must be lifted all at once; no side can rise before another. So it is very important to find the centre of gravity and connect the rope exactly to that point. The stone has a polygonal shape and its height is the same throughout the whole polygonal area. Your task is to find the centre of gravity for the given polygon.
Input
The input consists of T test cases. The number of them (T) is given on the first line of the input file. Each test case begins with a line containing a single integer N (3 <= N <= 1000000) indicating the number of points that form the polygon. This is followed by N lines, each containing two integers Xi and Yi (|Xi|, |Yi| <= 20000). These numbers are the coordinates of the i-th point. When we connect the points in the given order, we get a polygon. You may assume that the edges never touch each other (except the neighboring ones) and that they never cross. The area of the polygon is never zero, i.e. it cannot collapse into a single line.
Output
Print exactly one line for each test case. The line should contain exactly two numbers separated by one space. These numbers are the coordinates of the centre of gravity. Round the coordinates to the nearest number with exactly two digits after the decimal point (0.005 rounds up to 0.01). Note that the centre of gravity may be outside the polygon, if its shape is not convex. If there is such a case in the input data, print the centre anyway.
Sample Input
245 00 5-5 00 -541 111 111 111 11
Sample Output
0.00 0.006.00 6.00
Source
Central Europe 1999
注:利用加权平均求值,即将每块三角形重心乘以面积的总和再除以多边形总面积。详解请百度。
#include<stdio.h>#include<math.h>#define P_MAX 20000+100 struct point{double x,y;}arr[P_MAX];double Area(point A,point B,point C){return ((B.x-A.x)*(C.y-A.y)-(C.x-A.x)*(B.y-A.y))/2;};int main(){int N;scanf("%d",&N);while(N--){int num;scanf("%d",&num);for(int i=0;i<num;i++){scanf("%lf%lf",&arr[i].x,&arr[i].y);}double SumArea=0;double SumLiftx=0;double SumLifty=0;for(int i=1;i<num-1;i++){double area=Area(arr[0],arr[i],arr[i+1]);SumLiftx+=(arr[0].x+arr[i].x+arr[i+1].x)*area;SumLifty+=(arr[0].y+arr[i].y+arr[i+1].y)*area; SumArea+=area;}printf("%.2lf %.2lf\n",SumLiftx/SumArea/3,SumLifty/SumArea/3);}return 0;}
0 0
- hdoj1115 Lifting the Stone
- 1115 Lifting the Stone
- HDU-Lifting the Stone
- HDU1115 Lifting the Stone
- HDU1115 Lifting the Stone
- pku 1385 Lifting the Stone
- HDU 1115 Lifting the Stone
- poj 1385 Lifting the Stone
- HDU 1115 Lifting the Stone
- hdu-1115-Lifting the Stone
- Lifting the Stone 7.1.3
- POJ 1385 Lifting the Stone
- hdu 1115 Lifting the Stone
- HDU 1115 Lifting the Stone
- HDU 1115 Lifting the Stone
- ZJU2015 Lifting the Stone - 任意多边形重心
- zoj 2105 || poj 1385 Lifting the Stone
- HDU 1115 Lifting the Stone 计算几何
- hdu - 4303 - Hourai Jeweled 树dp
- HDU 4247 A Famous ICPC Team
- 最小(大)生成树_裸题(HDU-1863,POJ-2377)
- cocos2dx-3.0(30) 动作进度 ProgressTimer
- ASP:Panel控件(容器控件)
- hdoj1115 Lifting the Stone
- poj 3253 fence repair
- 架构资料
- gets(s)、getchar()和scanf("%s",s)
- 在ubuntu 12.04 上安装openCV 2.4.9 (wandboard-quad iMX6 ARM9 quadcore)
- 876754653454
- ASP:FileUpload控件(文件上传控件)
- Container With Most Water
- jQuery 数据操作函数