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. word文档下划线无法显示的解决方法

    在编辑文档的时候经常会遇到下划线无法显示的情况,如图: 如果遇到不能在姓名后面加下划线的情况,我们该怎么做? 请看下面的图解: 1.首先点击左上角的office图标 2.点击右下角“word选项” 3 ...

  2. 转载:Google 官方应用架构的最佳实践指南 赞👍

    官方给的实践指南,很有实际的指导意义,  特别是对一些小公司,小团队,给了很好的参考意义. 原文地址: https://developer.android.com/topic/libraries/ar ...

  3. Scrapy项目之User timeout caused connection failure(异常记录)

    Windows 10家庭中文版,Python 3.6.4,Scrapy 1.5.0, 提示:此文存在问题,真正测试, 请勿阅读, 07-14 14:26更新: 经过两个多小时的测试,发现此问题的原因是 ...

  4. Python的set集合详解

    Python 还包含了一个数据类型 -- set (集合).集合是一个无序不重复元素的集.基本功能包括关系测试和消除重复元素.集合对象还支持 union(联合),intersection(交),dif ...

  5. Dropout caffe源码

    GPU和CPU实现的不一样,这里贴的是CPU中的drop out 直接看caffe里面的源码吧:(产生满足伯努利分布的随机数mask,train的时候,data除以p,...... scale_ = ...

  6. inherited 的研究。

    结论: 1. inherited默认调用的是父类的同名 同参数方法.(常用,如果是同名 同参数方法 比如 overide 的,可以省略,只写个inherited就可.) 2. 子类的方法里可以 inh ...

  7. C++有super关键字么?

    很多人在学习Java之后,看到Java里面有super关键字,用来表示父类,那么C++里面有super关键字么? 答案是否定的.这也很容易理解,C++由于支持多继承,所以假设存在super关键字,那么 ...

  8. Solr的入门知识

      一.Solr的简介 Solr 是Apache下的一个顶级开源项目,采用Java开发,它是基于Lucene的全文搜索服务.Solr可以独立运行在Jetty.Tomcat等这些Servlet容器中.都 ...

  9. require demo 记录备份

    预览地址 http://127.0.0.1:8020/requireDemo/myNEW/index.html 注意 远程的 非模块的 empty: demo2

  10. 为什么Java中Long类型的比float类型的范围小?

    为什么Long类型的比float类型的范围小? 2015-09-15 22:36 680人阅读 评论(0) 收藏 举报 版权声明:本文为博主原创文章,未经博主允许不得转载. 作为一个常识,我们都知道浮 ...