D - Blast the Enemy!

Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Description

A new computer game has just arrived and as an active and always-in-the-scene player, you should finish it before the next university term starts. At each stage of this game, you have to shoot an enemy robot on its weakness point. The weakness point of a robot is always the ``center of mass" of its 2D shape in the screen. Fortunately, all robot shapes are simple polygons with uniform density and you can write programs to calculate exactly the center of mass for each polygon.

Let's have a more formal definition for center of mass (COM). The center of mass for a square, (also circle, and other symmetric shapes) is its center point. And, if a simple shape C is partitioned into two simple shapes A and B with areas SA and SB , then COM(C) (as a vector) can be calculated by

COM( C) = .

As a more formal definition, for a simple shape A with area SA :

COM( A) =

Input

The input contains a number of robot definitions. Each robot definition starts with a line containing n , the number of vertices in robot's polygon (n100) . The polygon vertices are specified in the next n lines (in either clockwise or counter-clock-wise order). Each of these lines contains two space-separated integers showing the coordinates of the corresponding vertex. The absolute value of the coordinates does not exceed 100. The case of n = 0 shows the end of input and should not be processed.

Output

The i -th line of the output should be of the form `` Stage #i:x y " (omit the quotes), where ( x, y ) is the center of mass for the i -th robot in the input. The coordinates must be rounded to exactly 6 digits after the decimal point.

Sample Input

4
0 0
0 1
1 1
1 0
3
0 1
1 0
2 2
8
1 1
2 1
2 7
3 7
3 0
0 0
0 7
1 7
0

Sample Output

Stage #1: 0.500000 0.500000
Stage #2: 1.000000 1.000000
Stage #3: 1.500000 3.300000
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 1001
const int inf=0x7fffffff; //无限大
int main()
{
int N;
double x[maxn],y[maxn],a[maxn],ax[maxn],ay[maxn],xg=,yg=,a1=,b1=,c=;
int t=;
while(cin>>N){
xg=,yg=,a1=,b1=,c=;
t++;
int i,n;
if(N==)
break;
for(i=;i<N;i++)
{
scanf("%lf %lf",&x[i],&y[i]);
}
for(i=;i<N-;i++)
{
a[i]=(y[i+]+y[i])*(x[i]-x[i+])/2.0;
ax[i]=(x[i+]*x[i+]+x[i+]*x[i]+x[i]*x[i])*(y[i+]-y[i])/6.0;
ay[i]=(y[i+]*y[i+]+y[i+]*y[i]+y[i]*y[i])*(x[i]-x[i+])/6.0;
}
a[N-]=(y[]+y[N-])*(x[N-]-x[])/2.0;
ax[N-]=(x[]*x[]+x[]*x[N-]+x[N-]*x[N-])*(y[]-y[N-])/6.0;
ay[N-]=(y[]*y[]+y[]*y[N-]+y[N-]*y[N-])*(x[N-]-x[])/6.0;
for(i=;i<N;i++)
{
a1=a1+ax[i];
b1=b1+a[i];
c=c+ay[i];
}
xg=a1/b1;
yg=c/b1;
printf("Stage #%d: %.6lf %.6lf\n",t,xg,yg);
}
return ;
}

UVALive 4426 Blast the Enemy! 计算几何求重心的更多相关文章

  1. UVALive 4426 Blast the Enemy! --求多边形重心

    题意:求一个不规则简单多边形的重心. 解法:多边形的重心就是所有三角形的重心对面积的加权平均数. 关于求多边形重心的文章: 求多边形重心 用叉积搞一搞就行了. 代码: #include <ios ...

  2. hdu-1115 计算几何 求重心 凸多边形 面积

    思想是分割成三角形,然后求三角形的重心.那么多边形重心就是若干个三角形的重心带权求中心,可以用质点质心公式. #include <cstdio> #include <iostream ...

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

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

  4. UVALive 4262——Trip Planning——————【Tarjan 求强连通分量个数】

    Road Networks Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Stat ...

  5. hdu1115【多边形求重心模板】

    1.质量集中在顶点上.n个顶点坐标为(xi,yi),质量为mi,则重心(∑( xi×mi ) / ∑mi, ∑( yi×mi ) / ∑mi) 2.质量分布均匀.这个题就是这一类型,算法和上面的不同. ...

  6. POJ 3855 计算几何·多边形重心

    思路: 多边形面积->任选一个点,把多边形拆成三角,叉积一下 三角形重心->(x1+x2+x3)/3,(y1+y2+y3)/3 多边形重心公式题目中有,套一下就好了 计算多边形重心方法: ...

  7. 多边形求重心 HDU1115

    http://acm.hdu.edu.cn/showproblem.php?pid=1115 引用博客:https://blog.csdn.net/ysc504/article/details/881 ...

  8. UVALive 7146 Defeat the Enemy(贪心+STL)(2014 Asia Shanghai Regional Contest)

    Long long ago there is a strong tribe living on the earth. They always have wars and eonquer others. ...

  9. 计算几何--求凸包模板--Graham算法--poj 1113

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 28157   Accepted: 9401 Description ...

随机推荐

  1. .net HttpCrawler

    using HtmlAgilityPack; using System; using System.Collections.Generic; using System.Diagnostics; usi ...

  2. linq和ef关于group by取最大值的两种写法

    LINQ: var temp = from p in db.jj_Credentials group p by p.ProfessionID into g select new { g.Key, Ma ...

  3. torchvision简介

    安装pytorch时,torchvision独立于torch.torchvision包由流行的数据集(torchvision.datasets).模型架构(torchvision.models)和用于 ...

  4. linux快速安装mysql教程

    #安装mysql服务器:yum install mysql-server #设置开机启动chkconfig mysqld on#现在启动服务service mysqld start #设置root初始 ...

  5. python网络编程--进程线程

    一:什么是进程 一个程序执行时的实例被称为一个进程. 每个进程都提供执行程序所需的资源.一个进程有一个虚拟地址空间.可执行代码.对系统对象的开放句柄.一个安全上下文.一个独特的进程标识符.环境变量.一 ...

  6. 分析new delete 的本质

    在程序设计中,数据可能会存在不同的内存空间,如函数栈 堆   全局变量区  ,今天我们来分析一下C++中堆分配方式和C语言的堆分配方式异同,从而更好的理解new  delete本质 C语言使用mall ...

  7. vue-cli脚手架安装

    -1.安装淘宝镜像 $ alias cnpm="npm --registry=https://registry.npm.taobao.org \ --cache=$HOME/.npm/.ca ...

  8. TypeScript的配置文件 tsconfig.json

    //tsconfig.json指定了用来编译这个项目的根文件和编译选项 { "compilerOptions": { //compilerOptions:编译选项,可以被忽略,这时 ...

  9. Web前端开发最佳实践(11):使用更严格的JavaScript编码方式,提高代码质量

    前言 JavaScript语言由于其固有的灵活性,所以导致开发者可以写出很多诡异的代码,甚至一些较为正常的特性,如类型隐式转换.this的指代等等,也会让刚接触此语言的开发者头大不已.尤其是那些熟知其 ...

  10. MFC+WinPcap编写一个嗅探器之七(协议)

    这一节是本系列教程的结尾了,内容也比较简单,主要是对网络协议进行分析,其实学过计算机网络的同学完全可以略过 在整个项目中需要有一个头文件存放各层协议的头部定义,我把它们放在了head.h中,这个头文件 ...