poj 2069 Super Star (模拟退火)
来源:互联网 发布:淘宝能直接微信支付吗 编辑:程序博客网 时间:2024/05/17 13:13
Super Star
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 5091 Accepted: 1266 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
Source
Japan 2001
[Submit] [Go Back] [Status] [Discuss]
题解:模拟退火
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#define eps 1e-9#define N 100#define T 100#define delta 0.98using namespace std;struct data{double x,y,z;}p[N];int n;double dx[10]={0,1,0,-1,0,0};double dy[10]={1,0,-1,0,0,0};double dz[10]={0,0,0,0,1,-1};double pow(double x){return x*x;}double getdis(data a,data b){return sqrt(pow(a.x-b.x)+pow(a.y-b.y)+pow(a.z-b.z));}int calc(data a){int poly=1;for (int i=2;i<=n;i++) if (getdis(a,p[poly])<getdis(a,p[i])) poly=i;return poly;}double search(){double ans=1e18;double t=T;data now=p[1];while (t>eps) { int m=calc(now); double tmp=getdis(now,p[m]);data a; a.x=now.x+(p[m].x-now.x)/tmp*t;a.y=now.y+(p[m].y-now.y)/tmp*t;a.z=now.z+(p[m].z-now.z)/tmp*t;ans=min(ans,tmp);now=a;t*=delta;}return ans;}int main(){while (true) {scanf("%d",&n);if (!n) break;for (int i=1;i<=n;i++) scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].z);printf("%.6lf\n",search());}}
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 2420 A Star not a Tree?(模拟退火)
- poj 2420 A Star not a Tree?(模拟退火)
- 【POJ 2420】 A Star not a Tree?(模拟退火)
- POJ 2420 A Star not a Tree? (模拟退火)
- poj 2420 A Star not a Tree? (模拟退火)
- poj 2069 Super Star
- Poj_2069_Super Star(模拟退火算法)
- POJ 2069 Super Star 爬山
- poj 2420 A Star not a Tree?(模拟退火求费马点)
- POJ 2420 A Star not a Tree? 费马点,模拟退火
- poj 2420 A Star not a Tree? 模拟退火
- 竖串问
- 关于移动端顶部吸附的
- intel向量化指令在矩阵乘应用中的评估
- 使用commandbuffer实现水流扰动效果
- Android开发 压缩保存图片至本地
- poj 2069 Super Star (模拟退火)
- [笔记]机器学习(Machine Learning) - 02.逻辑回归(Logistic Regression)
- 好久没来了,以后一直更新学习!!
- Hibernate的环境搭建以及简单操作
- 01 Effective Java 系列-创建和销毁对象
- 字符串1
- 入门源码
- 1.6、struct和union
- (原)SQL Server 系统提供功能的三个疑惑