题目大意:

给定三位空间上的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. php修改密码

      为了让页面更为好看一些,我一般会选择bootstrap,写起来虽然看着麻烦,但是我们真正需要的只有中间的内容  下面是html的内容 <div id="tbx"" ...

  2. javascript修改图片链接地址

    <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head>    < ...

  3. Redis主从、事务、哨兵、消息、代理分片

    安装 wget http://download.redis.io/releases/redis-3.0.5.tar.gz tar -zxvf redis-3.0.5.tar.gz cd redis-3 ...

  4. zipkin环境搭建

    基于jdk1.8 下载zipkin jar包 用wget下载zipkin官方最新jar包 wget -O zipkin.jar 'https://search.maven.org/remote_con ...

  5. 九度OJ 1207:质因数的个数 (质数)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5939 解决:1926 题目描述: 求正整数N(N>1)的质因数的个数. 相同的质因数需要重复计算.如120=2*2*2*3*5,共有 ...

  6. php自定义函数: amr转mp3格式

    <?php function amr2mp3($file){ if (file_exists($file . '.mp3') == true) { return; } else { $param ...

  7. 加密php源代码

    <?php function RandAbc($length = "") { //返回随机字符串 $str = "ABCDEFGHIJKLMNOPQRSTUVWXY ...

  8. Django利用form进行显示

    form的显示部分主要分为2部分:1.统一显示(表单里的所有字段): a.{{form.as_table}} b.{{form.as_p}}2.显示部分字段: {{ field.label_tag } ...

  9. 【python】将excel转成json

    excel格式如下: 转换后如下 {"BD": 1375.0, "BE": 829.0, "BF": 3.0, "BG" ...

  10. linux查看当前文件夹下每个文件大小

    查看当前文件夹下每个文件大小 并会给出当前文件大小总和,后面加具体的文件名会显示具体的文件大小 ls -lht 把*换成具体的文件名会显示具体的文件大小 du -sh *