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.

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.

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.
 
题目大意:给n个点,求能包含这n个点的最小的球的半径
思路:传说中的模拟退火算法,不断逼近最优解
 
#include <cstdio>
#include <cmath> const int MAXN = 50;
const double EPS = 1e-6; struct Point3D {
double x, y, z;
Point3D(double xx = 0, double yy = 0, double zz = 0):
x(xx), y(yy), z(zz) {}
}; Point3D operator - (const Point3D &a, const Point3D &b) {
return Point3D(a.x - b.x, a.y - b.y, a.z - b.z);
} double dist(const Point3D &a, const Point3D &b) {
Point3D c = a - b;
return sqrt(c.x * c.x + c.y * c.y + c.z * c.z);
} Point3D p[MAXN];
int n; void solve() {
Point3D s;
double delta = 100, ans = 1e20;
while(delta > EPS) {
int d = 0;
for(int i = 1; i < n; ++i)
if(dist(s, p[i]) > dist(s,p[d])) d = i;
double maxd = dist(s, p[d]);
if(ans > maxd) ans = maxd;
s.x += (p[d].x - s.x)/maxd*delta;
s.y += (p[d].y - s.y)/maxd*delta;
s.z += (p[d].z - s.z)/maxd*delta;
delta *= 0.98;
}
printf("%.5f\n", ans);
} int main() {
while(scanf("%d", &n) != EOF && n) {
for(int i = 0; i < n; ++i) scanf("%lf%lf%lf", &p[i].x, &p[i].y, &p[i].z);
solve();
}
}

  

 

POJ 2069 Super Star(计算几何の最小球包含+模拟退火)的更多相关文章

  1. poj 2069 Super Star——模拟退火(收敛)

    题目:http://poj.org/problem?id=2069 不是随机走,而是每次向最远的点逼近.而且也不是向该点逼近随意值,而是按那个比例:这样就总是接受,但答案还是要取min更新. 不知那个 ...

  2. poj 2069 Super Star —— 模拟退火

    题目:http://poj.org/problem?id=2069 仍是随机地模拟退火,然而却WA了: 看看网上的题解,都是另一种做法——向距离最远的点靠近: 于是也改成那样,竟然真的A了...感觉这 ...

  3. POJ 2069 Super Star

    模拟退火. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm& ...

  4. poj 2069 Super Star 模拟退火

    题目大意: 给定三位空间上的n(\(n \leq 30\))个点,求最小的球覆盖掉所有的点. 题解: 貌似我们可以用类似于二维平面中的随机增量法瞎搞一下 但是我不会怎么搞 所以我们模拟退火就好了啊QA ...

  5. 【POJ】2069.Super Star

    题解 求一个最小的半径的球,包括三维平面上所有的点,输出半径 随机移动球心,半径即为距离最远的点,移动的方式是向离的最远的那个点移动一点,之后模拟退火就好 代码 #include <iostre ...

  6. Super Star(最小球覆盖)

    Super Star http://poj.org/problem?id=2069 Time Limit: 1000MS   Memory Limit: 65536K Total Submission ...

  7. POJ 2069 模拟退火算法

    Super Star Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6422   Accepted: 1591   Spec ...

  8. 三分 POJ 2420 A Star not a Tree?

    题目传送门 /* 题意:求费马点 三分:对x轴和y轴求极值,使到每个点的距离和最小 */ #include <cstdio> #include <algorithm> #inc ...

  9. POJ 2420 A Star not a Tree? (计算几何-费马点)

    A Star not a Tree? Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3435   Accepted: 172 ...

随机推荐

  1. C++笔记011:C++对C的扩展——变量检测增强

    原创笔记,转载请注明出处! 点击[关注],关注也是一种美德~ 在C语言中重复定义多个同名的变量是合法的,多个同名的全局变量最终会被链接到全局数据区的同一个地址空间上. 在C++中,不允许定义多个同名的 ...

  2. 编程界失传秘术,SSO单点登录,什么是单点,如何实现登录?

    单点登录 多系统,单一位置登录,实现多系统同时登录的一种技术. 常出现在互联网应用和企业级平台中. 如:京东. 单点登录一般是用于互相授信的系统,实现单一位置登录,全系统有效的. 三方登录:某系统,使 ...

  3. 免安装版MySQL8数据库的安装

    [环境准备] PC版本:Windows10企业版.64位操作系统 数据库:MySQL8.0.12-win64.zip免安装版 [彻底卸载已安装的MySQL数据库] 由于系统中MySQL数据库的卸载不彻 ...

  4. (八)netty的SSL renegotiation攻击漏洞

    为了满足安全规范,从http改造成https(见(四)启用HTTPS),然而启用https后就可以高枕无忧了吗?绿盟告诉你:当然不,TLS Client-initiated 重协商攻击(CVE-201 ...

  5. FileBeats安装

    FileBeats安装 FileBeats官方下载链接: https://www.elastic.co/downloads/beats/filebeat 也可以直接使用以下命令下载(文章下载目录一概为 ...

  6. WIN10下WNMP开发环境部署

    刚刚开始学习PHP时,一直使用phpstudy,后面发现很多东西自己单独配置安装会理解更深刻,所以自己总结了一下windows下开发环境的部署教程. 以前经常在CSDN和博客园看别人的教程,今天才注册 ...

  7. (mark)ubuntu16.04下安装&配置anaconda+tensorflow新手教程

    https://blog.csdn.net/m0_37864814/article/details/82112029

  8. python 感叹号的作用

    1.     !表示反转逻辑表达式的值 2.      打印格式控制中: x!r代表repr(x),x!s代表str(x),x!a代表ascii(x)

  9. JavaSE思维导图

    Java基础知识:  面向对象:  集合:  多线程.网络编程.反射.设计模式:  常用API:  转载 https://blog.csdn.net/qq_34983808/article/detai ...

  10. Splay初学习

    例题传送门 听YZ哥哥说Splay是一种很神奇的数据结构,所以学习了一下它的最基本操作.O(1)的Spaly. 伸展树(Splay Tree),也叫分裂树,是一种二叉排序树,它能在O(logn)内完成 ...