UVALive 4426 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

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

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! 计算几何求重心的更多相关文章
- UVALive 4426 Blast the Enemy! --求多边形重心
题意:求一个不规则简单多边形的重心. 解法:多边形的重心就是所有三角形的重心对面积的加权平均数. 关于求多边形重心的文章: 求多边形重心 用叉积搞一搞就行了. 代码: #include <ios ...
- hdu-1115 计算几何 求重心 凸多边形 面积
思想是分割成三角形,然后求三角形的重心.那么多边形重心就是若干个三角形的重心带权求中心,可以用质点质心公式. #include <cstdio> #include <iostream ...
- Lifting the Stone 计算几何 多边形求重心
Problem Description There are many secret openings in the floor which are covered by a big heavy sto ...
- UVALive 4262——Trip Planning——————【Tarjan 求强连通分量个数】
Road Networks Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Stat ...
- hdu1115【多边形求重心模板】
1.质量集中在顶点上.n个顶点坐标为(xi,yi),质量为mi,则重心(∑( xi×mi ) / ∑mi, ∑( yi×mi ) / ∑mi) 2.质量分布均匀.这个题就是这一类型,算法和上面的不同. ...
- POJ 3855 计算几何·多边形重心
思路: 多边形面积->任选一个点,把多边形拆成三角,叉积一下 三角形重心->(x1+x2+x3)/3,(y1+y2+y3)/3 多边形重心公式题目中有,套一下就好了 计算多边形重心方法: ...
- 多边形求重心 HDU1115
http://acm.hdu.edu.cn/showproblem.php?pid=1115 引用博客:https://blog.csdn.net/ysc504/article/details/881 ...
- 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. ...
- 计算几何--求凸包模板--Graham算法--poj 1113
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 28157 Accepted: 9401 Description ...
随机推荐
- Cloud Lab: 泰晓实验云台【转】
转自:http://tinylab.org/cloud-lab/ 可快速构建的计算机课程在线实验平台 由 Wu Zhangjin 创建于 2017/10/06 评论 打赏 项目描述 泰晓实验云台 项目 ...
- Linux下如何在进程中获取虚拟地址对应的物理地址【转】
转自:http://blog.csdn.net/kongkongkkk/article/details/74366200 如果让你编写一个程序,来获取虚拟地址对应的物理地址..你会试着操作MMU吗.. ...
- HDU 2825 Wireless Password
题目链接:HDU-2825 题意:给出m个单词,要构造出满足包含其中大于等于k个单词的字符串,字符只包括小写字母,问长度为n的这样的串有多少个. 思路:令dp[i][j][k]表示当前已经构造了i个字 ...
- centos7 yum搭建lamp环境
=============================================== 2018/1/14_第1次修改 ccb_warlock == ...
- python面向对象(四)之抽象类与接口
学过java的应该知道java有抽象类和接口的那么python呢?(以前写的关于java抽象类的笔记java抽象类与接口) python作为一个动态语言,没有强类型的检查,而是以鸭子类型的方式提现 ...
- tensorflow中的boolean_mask
将mask中所有为true的抽取出来,放到一起,这里从n维降到1维度 tensor = [[1, 2], [3, 4], [5, 6]] import numpy as np mask=np.arra ...
- elasticsearch5.5-head
修改 elasticsearch/config/elasticsearch.yml 添加 http.cors.enabled: true http.cors.allow-origin: "* ...
- MySQL学习笔记:concat、concat_ws、group_concat —— 字符串连接
在MySQL中,实现字符串拼接主要有以下3种函数: concat(x,y,...) concat_ws(分隔符,x,y,...) group_concat(distinct xxx order by ...
- HBase 入门笔记-数据落地篇
一.前言 关于数据落地方面,HBase官网也有相关介绍.本文主要介绍一下实际工作中涉及的数据存储方面的一些经验和技巧,主要涉及表rowkey设计.数据落地方案 二.表设计 相对于MySQL等关系型数据 ...
- jquery validate不用submit提交,用js提交的
jquery validate控件 默认是使用submit提交的, 要想改成使用button的click事件处理函数中手工提交, 可以按照如下方式操作: 1 绑定form的validate, 2 然后 ...