技术笔记:UVALive4426BlasttheEnemy!计算几何求重心

简介: 技术笔记:UVALive4426BlasttheEnemy!计算几何求重心

D - Blast the Enemy!


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


Submit Status Practice UVALive 4426


Description


A new computer game has //代码效果参考:http://www.lyjsj.net.cn/wz/art_23104.html

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.</p> <p>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 </p> <p>COM( C) = .</p> <p>As a more formal definition, for a simple shape A with area SA : </p> <p>COM( A) = </p> <p>Input</p> <p>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 //代码效果参考:http://www.lyjsj.net.cn/wz/art_23094.html<p></p> 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. </p> <p>Output</p> <p>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


#include


#include


#include


#include


#include


#include [span style="color: rgba(0, 0, 255, 1)">set

#include


#include


#include


#include


#include


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=0,yg=0,a1=0,b1=0,c=0;


int t=0;


while(cin]N){


xg=0,yg=0,a1=0,b1=0,c=0;


t++;


int i,n;


if(N==0)


break;


for(i=0;i

{


scanf("%lf %lf",&x【i】,&y【i】);


}


for(i=0;i

{


a【i】=(y【i+1】+y【i】)(x【i】-x【i+1】)/2.0;


ax【i】=(x【i+1】x【i+1】+x【i+1】x【i】+x【i】x【i】)(y【i+1】-y【i】)/6.0;


ay【i】=(y【i+1】y【i+1】+y【i+1】y【i】+y【i】y【i】)(x【i】-x【i+1】)/6.0;


}


a【N-1】=(y【0】+y【N-1】)(x【N-1】-//代码效果参考:http://www.lyjsj.net.cn/wx/art_23102.html

x【0】)/2.0;

ax【N-1】=(x【0】x【0】+x【0】x【N-1】+x【N-1】x【N-1】)(y【0】-y【N-1】)/6.0;


ay【N-1】=(y【0】y【0】+y【0】y【N-1】+y【N-1】y【N-1】)(x【N-1】-x【0】)/6.0;


for(i=0;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 0;


}

相关文章
|
XML 应用服务中间件 Apache
Tomcat AJP连接器配置secretRequired=“true“,但是属性secret确实空或者空字符串,这样的组合是无效的。
Tomcat AJP连接器配置secretRequired=“true“,但是属性secret确实空或者空字符串,这样的组合是无效的。
|
JavaScript 应用服务中间件 nginx
vuecli3打包项目上线之后报错怎么使用本地的sourcemap文件定位调试?
vuecli3打包项目上线之后报错怎么使用本地的sourcemap文件定位调试?
374 0
|
运维 应用服务中间件 网络安全
自动化运维的魔法:使用Ansible进行服务器配置管理
【9月更文挑战第13天】在这篇文章中,我们深入探讨如何利用Ansible这一强大的自动化工具来简化和加速你的服务器配置管理工作。我们将从基础概念出发,逐步引导你了解如何使用Ansible编写Playbooks,实现对服务器群的快速部署、配置更新与维护任务。通过实际案例,你将看到Ansible如何节省时间、减少人为错误并提高运维效率。无论你是初学者还是有经验的运维工程师,这篇文章都将带给你新的视角和启发。
|
测试技术 网络安全
什么是软件测试? 软件测试都有什么岗位 ?软件测试和调试的区别? 软件测试和开发的区别? 一位优秀的测试人员应该具备哪些素质? 软件测试等相关概念入门篇
文章全面介绍了软件测试的基本概念、目的、岗位分类、与开发和调试的区别,并阐述了成为优秀测试人员应具备的素质和技能。
1560 1
什么是软件测试? 软件测试都有什么岗位 ?软件测试和调试的区别? 软件测试和开发的区别? 一位优秀的测试人员应该具备哪些素质? 软件测试等相关概念入门篇
|
数据挖掘 索引 Python
Pandas中的crosstab:轻松构建交叉表
Pandas中的crosstab:轻松构建交叉表
444 0
|
设计模式 安全 Java
【C++】特殊类设计
【C++】特殊类设计
|
机器学习/深度学习 数据采集 算法
【机器学习】线性回归:以房价预测为例
【机器学习】线性回归:以房价预测为例
1036 1
|
存储 运维 Java
nacos常见问题之nacos提示ack server push request如何解决
Nacos是阿里云开源的服务发现和配置管理平台,用于构建动态微服务应用架构;本汇总针对Nacos在实际应用中用户常遇到的问题进行了归纳和解答,旨在帮助开发者和运维人员高效解决使用Nacos时的各类疑难杂症。
|
微服务
注册中心机制
【2月更文挑战第16天】注册中心机制
166 5