poj 2069 Super Star
来源:互联网 发布:网络记事本哪个好用 编辑:程序博客网 时间:2024/06/07 01:50
Super Star
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 3396 Accepted: 902 Special Judge
Description
During a voyage of the starship Hakodate-maru (see Problem 1406), researchers found strange synchronized movements of stars. Having heard these observations, Dr. Extreme proposed a theory of "super stars". Do not take this term as a description of actors or singers. It is a revolutionary theory in astronomy.
According to this theory, starts we are observing are not independent objects, but only small portions of larger objects called super stars. A super star is filled with invisible (or transparent) material, and only a number of points inside or on its surface shine. These points are observed as stars by us.
In order to verify this theory, Dr. Extreme wants to build motion equations of super stars and to compare the solutions of these equations with observed movements of stars. As the first step, he assumes that a super star is sphere-shaped, and has the smallest possible radius such that the sphere contains all given stars in or on it. This assumption makes it possible to estimate the volume of a super star, and thus its mass (the density of the invisible material is known).
You are asked to help Dr. Extreme by writing a program which, given the locations of a number of stars, finds the smallest sphere containing all of them in or on it. In this computation, you should ignore the sizes of stars. In other words, a star should be regarded as a point. You may assume the universe is a Euclidean space.
According to this theory, starts we are observing are not independent objects, but only small portions of larger objects called super stars. A super star is filled with invisible (or transparent) material, and only a number of points inside or on its surface shine. These points are observed as stars by us.
In order to verify this theory, Dr. Extreme wants to build motion equations of super stars and to compare the solutions of these equations with observed movements of stars. As the first step, he assumes that a super star is sphere-shaped, and has the smallest possible radius such that the sphere contains all given stars in or on it. This assumption makes it possible to estimate the volume of a super star, and thus its mass (the density of the invisible material is known).
You are asked to help Dr. Extreme by writing a program which, given the locations of a number of stars, finds the smallest sphere containing all of them in or on it. In this computation, you should ignore the sizes of stars. In other words, a star should be regarded as a point. You may assume the universe is a Euclidean space.
Input
The input consists of multiple data sets. Each data set is given in the following format.
n
x1 y1 z1
x2 y2 z2
. . .
xn yn zn
The first line of a data set contains an integer n, which is the number of points. It satisfies the condition 4 <= n <= 30.
The location of n points are given by three-dimensional orthogonal coordinates: (xi, yi, zi) (i = 1, ..., n). Three coordinates of a point appear in a line, separated by a space character. Each value is given by a decimal fraction, and is between 0.0 and 100.0 (both ends inclusive). Points are at least 0.01 distant from each other.
The end of the input is indicated by a line containing a zero.
n
x1 y1 z1
x2 y2 z2
. . .
xn yn zn
The first line of a data set contains an integer n, which is the number of points. It satisfies the condition 4 <= n <= 30.
The location of n points are given by three-dimensional orthogonal coordinates: (xi, yi, zi) (i = 1, ..., n). Three coordinates of a point appear in a line, separated by a space character. Each value is given by a decimal fraction, and is between 0.0 and 100.0 (both ends inclusive). Points are at least 0.01 distant from each other.
The end of the input is indicated by a line containing a zero.
Output
For each data set, the radius of the smallest sphere containing all given points should be printed, each in a separate line. The printed values should have 5 digits after the decimal point. They may not have an error greater than 0.00001.
Sample Input
410.00000 10.00000 10.0000020.00000 10.00000 10.0000020.00000 20.00000 10.0000010.00000 20.00000 10.00000410.00000 10.00000 10.0000010.00000 50.00000 50.0000050.00000 10.00000 50.0000050.00000 50.00000 10.000000
Sample Output
7.0710734.64102
计算几何有一种很神奇的算法,叫做模拟退火,这个算法的名字听起来就很霸气,来源于热力学,是一种概率算法,理论上可以证明该算法得到全局最优解的概率为1.
但对于一个计算机专业的来说,很难理解这个过程,恐怕得加上物理系和数学系的,才能理解该算法。因此,其实我对该算法也是一知半解。对于具体的题目来说,算法设计过程会有差别,至于为什么这么设计,就很难说了,而且由于是概率算法,里面的一些参数取得不好,就会WA,至于到底取多少,不同的题目都是不一样的,个人测试下来,感觉比较难取。
虽然该算法是有一般流程,就给定一个初始温度,和降温幅度(这个取多少,看造化了),然后每次会产生一系列的马尔科夫序列(不懂自己百度去),按照什么规则产生(不知道),有一定概率接受该值作为新的迭代初值,按照正规的算法是一个min(1,exp(-delta/T))>rand(),其中rand属于[0,1]随机分布的实数,但实际网上的解题程序中往往都没有这个所谓的接受概率,并且我尝试写过这个标准的写法,结果死都不能AC,实在无语啊。至于为什么这样,貌似有种说法,是让其跳出局部最优解,达到全局最优解。
真的想理解该算法,不是那么容易的,想灵活运用也没有那么容易。
来看道题吧,空间给定若干点,求一个最小半径的球包含所有点。这题居然可以用模拟退火。。。真是想不到啊,这个马尔科夫序列是什么?看别人AC的代码,就是在沿着每次最大半径缩进一部分距离。这个是为什么?不清楚了,然后莫名其妙的AC了。
代码:
#include<cstdio>#include<iostream>#include<cmath>#define eps 1e-8using namespace std;struct point{ double x,y,z;}p[40],s;inline double dis(point &a,point &b){ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z));}void solve(int n){ s.x=s.y=s.z=0; double ans=1<<30,delta=1LL<<60; while(delta>eps){ int d=0; for(int i=0;i<n;i++) if(dis(s,p[i])>dis(s,p[d])) d=i; double dt=dis(s,p[d]); ans=min(ans,dt); s.x+=(p[d].x-s.x)/dt*delta; s.y+=(p[d].y-s.y)/dt*delta; s.z+=(p[d].z-s.z)/dt*delta; delta*=0.99; } printf("%.5f\n",ans);}int main(){ int n; while(scanf("%d",&n),n){ for(int i=0;i<n;i++) scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].z); solve(n); }return 0;}
0 0
- poj 2069 Super Star
- POJ 2069 Super Star 爬山
- poj 2069 super star 模拟退火
- POJ, 2069 Super Star(模拟退火算法)
- POJ 2069 Super Star(模拟退火)
- poj 2069 Super Star (模拟退火)
- 模拟退火初探--POJ 2069 Super Star
- [POJ 2069]Super Star(爬山搜索、最小球覆盖)
- [省选前题目整理][POJ 2069]Super Star(爬山搜索)
- POJ 2069 Super Star(模拟退火,最小球覆盖)
- POJ 2069 super star(三维点集最小圆覆盖 模拟退火)
- Super Star----Lunar版
- poj2069 Super Star
- You are my super star!!!!!!!!!!!!!!
- poj 2352 Star
- POJ 2532 Star
- Poj 2352 Star
- (题解)(搜索)POJ2069 Super Star
- C++ primer 第五版 中文版 练习 11.32 个人code
- 限速之TC
- java try catch finally
- linux cp 命令
- 数据结构java版一 预备知识
- poj 2069 Super Star
- redhat server 5.5 安装 git
- DELPHI判断同时按下CTRL+SHIFT组合键
- 利用 Ant 和 Eclipse 有效地提高部署工作效率
- RestTemplate的用法
- 2014校园招聘之四(Google的面试题)
- 1000 A+B
- Unreal Engine 4 C++ 射线碰撞
- 前端学习资料汇总