题目大意:

给定三位空间上的n(\(n \leq 30\))个点,求最小的球覆盖掉所有的点.

题解:

貌似我们可以用类似于二维平面中的随机增量法瞎搞一下

但是我不会怎么搞

所以我们模拟退火就好了啊QAQ

#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
inline void read(int &x){
x=0;char ch;bool flag = false;
while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
inline int cat_max(const int &a,const int &b){return a>b ? a:b;}
inline int cat_min(const int &a,const int &b){return a<b ? a:b;}
const int maxn = 45;
const double eps = 1e-15;
const double det = 0.99;
struct Point{
double x,y,z;
Point(const double &a=0,const double &b=0,const double &c=0){
x=a;y=b;z=c;
}
};
inline double dis(const Point &a,const 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));
}
int n;double ans = 1e100;
Point p[maxn];
inline double f(const Point &x){
double ret = 0;
for(int i=1;i<=n;++i) ret = max(ret,dis(x,p[i]));
if(ret < ans) ans = ret;
return ret;
}
inline double ran(){
return (rand() % 1000 + 1)/1000.0;
}
Point nw;
int main(){
srand(2333);
while(1){
read(n);if(n == 0) break;
nw.x = nw.y = nw.z = 0;
ans = 1e100;
for(int i=1;i<=n;++i){
scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].z);
}
double T = 100.0,x;
double dist;int pos;
while(T > eps){
dist = 0.0;
for(int i=1;i<=n;++i){
if(dist < dis(nw,p[i])){
pos = i;dist = dis(nw,p[i]);
}
}
Point nx(
nw.x+(p[pos].x-nw.x)/dist*T,
nw.y+(p[pos].y-nw.y)/dist*T,
nw.z+(p[pos].z-nw.z)/dist*T
);
x = f(nw) - f(nx);
if(x > 0 || exp(x/T) > ran()) nw = nx;
T *= det;
}
printf("%.5lf\n",ans);
}
getchar();getchar();
return 0;
}

poj 2069 Super Star 模拟退火的更多相关文章

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

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

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

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

  3. POJ 2069 Super Star(计算几何の最小球包含+模拟退火)

    Description During a voyage of the starship Hakodate-maru (see Problem 1406), researchers found stra ...

  4. POJ 2069 Super Star

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

  5. 【POJ】2069.Super Star

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

  6. POJ 2069 模拟退火算法

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

  7. Super Star(最小球覆盖)

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

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

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

  9. [POJ2069]Super Star(模拟退火)

    题目链接:http://poj.org/problem?id=2069 题意:求一个半径最小的球,使得它可以包围住所有点. 模拟退火,圆心每次都去找最远那个点,这样两点之间的距离就是半径,那么接下来移 ...

随机推荐

  1. hdu_1226超级密码(BFS)

    超级密码 Problem Description Ignatius花了一个星期的时间终于找到了传说中的宝藏,宝藏被放在一个房间里,房间的门用密码锁起来了,在门旁边的墙上有一些关于密码的提示信息:密码是 ...

  2. 智能家居DIY-空气质量检测篇-获取空气污染指数

    前言 话说楼主终于升级当爸了,宝宝现在5个月了,宝宝出生的时候是冬天,正是魔都空气污染严重的时候,当时就想搞个自动开启空气净化器,由于种种原因一直没有时间搞,最近终于闲下来了这个事情终于提上议程了,现 ...

  3. iOS 导航引发坐标高度问题

    iOS7 后导航结构发生变化,有新的控制属性诞生,一下为两个属性引发的控制器视图高度问题 translucent  = YES  导航透明    (默认) translucent  = NO   导航 ...

  4. shell基础part2

    shell基础 一.bash中的变量 1.变量的定义:变量是计算机的内存单元,其中存放的值是可以改变的. 2.变量的设定规则:变量名不能以数字开头:变量的等号两边不能有空格,变量的值如果想有空格必须用 ...

  5. CAS的实现Atomic类库

    atomic 原子(atomic)本意是"不能被进一步分割的最小粒子",而原子操作(atomic operation)意为"不可被中断的一个或一系列操作".在多 ...

  6. 3.09课·········for穷举和迭代

    for循环拥有两类:穷举和迭代穷举:把所有可能的情况都走一遍,使用if条件筛选出来满足条件的情况. 1.单位给发了一张150元购物卡,拿着到超市买三类洗化用品.洗发水15元,香皂2元,牙刷5元.求刚好 ...

  7. OSI 与 TCP/IP

    OSI参考模型 物理层(Physical Layer) --- 数据表示.物理层规定了激活.维持.关闭通信端点之间的机械特性.电气特性.               功能特性以及过程特性.该层为上层协 ...

  8. jenkins实现自动部署

    主机A搭建gitlab.gitlab下载:https://www.gitlab.cc/downloads/    (gitlab中文网) 主机B搭建jenkinsjenkins下载:https://j ...

  9. tomcat异常处理经验汇总

    1.Https: Feb 21, 2018 5:22:02 PM org.apache.coyote.AbstractProtocol initSEVERE: Failed to initialize ...

  10. 改进地图的vo类

    现在的地图只是各帧特征点的集合.创建地图:局部,全局.局部:只相机位置附近的特征点,用来和当前帧匹配求解相机位置的.全局:不定位,回环检测和地图表达.重点或麻烦:维护局部地图的规模.为了实时,保证地图 ...