技术笔记: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;


}

相关文章
|
9天前
技术好文共享:蒙提霍尔悖论(三门问题)终极分析
技术好文共享:蒙提霍尔悖论(三门问题)终极分析
12 1
|
13天前
|
Java C# 开发者
在代码的海洋中航行:我的编程之旅
编程,一种将逻辑思维与创造力结合的艺术。它不仅是计算机语言的堆砌,更是解决问题的钥匙。本文将通过个人经历探讨编程的美学、挑战与收获,以及如何持续学习与适应技术变革的步伐。
|
2天前
|
机器学习/深度学习 算法 搜索推荐
代码之舞:探索编程艺术的深层美学
在数字世界的舞台上,编程不仅是技术的体现,更是艺术的一种展现。本文将深入探讨编程背后的艺术性,从算法的优雅到代码的简洁,揭示如何通过技术实现创造性思维的飞跃。我们将一起走进编程的世界,感受它在解决问题过程中所展现出的独特魅力和美学价值。
|
26天前
|
机器学习/深度学习 算法 搜索推荐
编程之舞:探索算法的优雅与力量
【6月更文挑战第10天】在软件的世界里,算法是构筑数字宇宙的基石。它们如同精心编排的舞蹈,每一个步骤都充满着逻辑的美感和解决问题的力量。本文将带领读者走进算法的世界,一起感受那些精妙绝伦的编程思想如何转化为解决现实问题的钥匙。
19 3
|
2月前
|
设计模式 算法 开发者
代码之美:探索编程艺术与实践的交汇点
【4月更文挑战第2天】 在数字世界的构建中,代码不仅仅是一种工具,它亦是艺术家手中的画笔。本文旨在探讨编程作为一种技术和艺术相结合的领域,揭示那些隐藏在代码背后的美学原则和创造力。我们将从编程的基础出发,逐步深入到设计模式、算法优雅性以及代码的可读性和维护性,最终探讨如何通过技术实现创新并解决问题。文章的目的是为那些渴望在技术实践中寻找创造性和美感的开发者提供灵感和指导。
|
11月前
|
算法 C++
走进“深度搜索基础训练“,踏入c++算法殿堂(二)
走进“深度搜索基础训练“,踏入c++算法殿堂(二)
56 0
|
11月前
|
机器学习/深度学习 算法 C++
走进“深度搜索基础训练“,踏入c++算法殿堂(五)
走进“深度搜索基础训练“,踏入c++算法殿堂(五)
65 0
|
2月前
|
算法 数据可视化 vr&ar
【图形学】探秘图形学奥秘:DDA与Bresenham算法的解密与实战
【图形学】探秘图形学奥秘:DDA与Bresenham算法的解密与实战
69 0
|
11月前
|
算法 C++
走进“深度搜索基础训练“,踏入c++算法殿堂(三)
走进“深度搜索基础训练“,踏入c++算法殿堂(三)
66 0
|
机器学习/深度学习 人工智能 自然语言处理
扩散模型背后数学太难了,啃不动?谷歌用统一视角讲明白了
扩散模型背后数学太难了,啃不动?谷歌用统一视角讲明白了
207 0