Lifting the Stone

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 230 Accepted Submission(s): 130
 
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
2
4
5 0
0 5
-5 0
0 -5
4
1 1
11 1
11 11
1 11
 
Sample Output
0.00 0.00
6.00 6.00
 
 
Source
Central Europe 1999
 
Recommend
Eddy
 
/*
给你一个多边形,然后让你求多边形的重心 初步思路:听了蒋金讲了一个重心加权平均求总重心,就是n边形,分割成n-2个小三角形,然后求出重心,面积;
用公式 求和Si*(Xi,Yi)/Sall 求出n边形的重心 #错误:加权平局的时候莫名地错 #错误反思点:double卡的精度问题,中间过程尽量不要出现先除又乘的问题,因为那样有double精度的问题会产生误差。 1e6的数据量只能遍历一边
*/
#include<bits/stdc++.h>
#define N 1000010
using namespace std;
struct Point{
double x,y;
Point(){}
Point(double a,double b){
x=a;
y=b;
}
void input(){
scanf("%lf%lf",&x,&y);
}
};
Point p;
int t,n;
vector<Point>v;//用来存储所有的点
vector<Point>Focus;//存放每个小三角形的重心
double s[N];//用来存放n-2个小三角形的面积
void init(){
v.clear();
Focus.clear();
}
double dis(Point a,Point b){//两点间距离
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
Point operation_Focus(){
double sall=;
Point p(,);
for(int i=;i<v.size()-;i++){//每个三角形由v[0],v[i],v[i+1]三个顶点组成
//面积
s[i-]=(v[i].x - v[].x)*(v[i+].y - v[].y) - (v[i].y-v[].y)*(v[i+].x - v[].x);
sall+=s[i-];
//cout<<"S="<<s[i-1]<<endl;
//重心
p.x+=s[i-]*(v[i].x+v[i+].x+v[].x)*1.0/;
p.y+=s[i-]*(v[i].y+v[i+].y+v[].y)*1.0/;
//cout<<"Point=("<<(fx*2+v[0].x)/3<<","<<(fy*2+v[0].y)/3<<")"<<endl;
}
p.x/=sall*1.0;
p.y/=sall*1.0;
return p;
}
int main(){
//freopen("in.txt","r",stdin);
scanf("%d",&t);
//cout<<t<<endl;
while(t--){
scanf("%d",&n);
//cout<<n<<endl;
init();
for(int i=;i<n;i++){
p.input();
//cout<<p.x<<" "<<p.y<<endl;
v.push_back(p);
}//将所有的点存入vector
p=operation_Focus();
printf("%.2f %.2f\n",p.x,p.y);
}
return ;
}

Lifting the Stone(求多边形的重心—)的更多相关文章

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

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

  2. POJ 1385 Lifting the Stone (多边形的重心)

    Lifting the Stone 题目链接: http://acm.hust.edu.cn/vjudge/contest/130510#problem/G Description There are ...

  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. poj 1115 Lifting the Stone 计算多边形的中心

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

  5. hdu_1115_Lifting the Stone(求多边形重心)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1115 题意:给你N个点围成的一个多边形,让你求这个多边形的重心. 题解: 将多边形划分为若干个三角形. ...

  6. HDU1115&&POJ1385Lifting the Stone(求多边形的重心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1115# 大意:给你个n,有n个点,然后给你n个点的坐标,求这n个点形成的多边形的重心的坐标. 直接套模 ...

  7. Lifting the Stone 计算几何 多边形求重心

    Problem Description There are many secret openings in the floor which are covered by a big heavy sto ...

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

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

  9. POJ1385 Lifting the Stone

    There are many secret openings in the floor which are covered by a big heavy stone. When the stone i ...

随机推荐

  1. 读Zepto源码之Gesture模块

    Gesture 模块基于 IOS 上的 Gesture 事件的封装,利用 scale 属性,封装出 pinch 系列事件. 读 Zepto 源码系列文章已经放到了github上,欢迎star: rea ...

  2. Nodejs最好的ORM - TypeORM

    TypeORM是一个采用TypeScript编写的用于Node.js的优秀ORM框架,支持使用TypeScript或Javascript(ES5, ES6, ES7)开发.目标是保持支持最新的Java ...

  3. Opengl4.5 中文手册—G

    索引 A      B    C      D     E     F     G H      I     J      K     L     M     N O      P    Q      ...

  4. Redisson分布式锁的简单使用

    一:前言 我在实际环境中遇到了这样一种问题,分布式生成id的问题!因为业务逻辑的问题,我有个生成id的方法,是根据业务标识+id当做唯一的值! 而uuid是递增生成的,从1开始一直递增,那么在同一台机 ...

  5. Tomcat启动错误【Error listenerStart】

    今天启动Tomcat启动不了,报以下错: org.apache.catalina.core.StandardContext startInternal SEVERE: Error listenerSt ...

  6. 快速搭建应用服务日志收集系统(Filebeat + ElasticSearch + kibana)

    快速搭建应用服务日志收集系统(Filebeat + ElasticSearch + kibana) 概要说明 需求场景,系统环境是CentOS,多个应用部署在多台服务器上,平时查看应用日志及排查问题十 ...

  7. bzoj1968 COMMON 约数研究

    Input只有一行一个整数 N(0 < N < 1000000).Output只有一行输出,为整数M,即f(1)到f(N)的累加和.Sample Input 3 Sample Output ...

  8. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)

    http://codeforces.com/contest/831 A. Unimodal Array time limit per test 1 second memory limit per te ...

  9. html表格宽度设置失效

    问题描述: 我在写一个网页table时,table宽度超过了我预想的宽度,我想把它设置小一点,但总是没效果.改到怀疑人生!代码如下: 经过多次调试后发现一个问题,table可以改变大小,但是会有一个最 ...

  10. Spring详解(七)------事务管理

    PS:本篇博客源码下载链接:http://pan.baidu.com/s/1mi3NhX2 密码:3io2 1.事务介绍 事务(Transaction),一般是指要做的或所做的事情.在计算机术语中是指 ...