题目大意:

给定三位空间上的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. BestCoder Round #63 (div.2)

    感觉有些无聊的比赛. A 暴力枚举下就行 B 简单的dp,但是wa了一发后就去先把C做了,然后发现如果输入的100个数,是如1,2,3,4,...,100,然后k=50,个数为c(100,50).果断 ...

  2. Python PhatomJS 和Selenium动态加载页面 获取图片内容

    如果您觉得感兴趣的话,可以添加我的微信公众号:一步一步学Python![](http://images2017.cnblogs.com/blog/993869/201711/993869-201711 ...

  3. iOS11 push控制器tabbar上移问题

    解决方法 - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated { // 如果有大 ...

  4. Netty Redis 亿级流量 高并发 实战 (长文 修正版)

    目录 疯狂创客圈 Java 分布式聊天室[ 亿级流量]实战系列之 -30[ 博客园 总入口 ] 写在前面 1.1. 快速的能力提升,巨大的应用价值 1.1.1. 飞速提升能力,并且满足实际开发要求 1 ...

  5. 【python】-- 面向对象引子、概念

    面向过程编程 1.编程范式 编程是 程序 员 用特定的语法+数据结构+算法组成的代码来告诉计算机如何执行任务的过程 , 一个程序是程序员为了得到一个任务结果而编写的一组指令的集合,正所谓条条大路通罗马 ...

  6. IE模式下背景图片不显示

    初衷是想给这个提交按钮<input type="submit" value=" />加上背景图片,用了以下css样式: .subtn input { back ...

  7. python+NLTK 自然语言学习处理六:分类和标注词汇一

    在一段句子中是由各种词汇组成的.有名词,动词,形容词和副词.要理解这些句子,首先就需要将这些词类识别出来.将词汇按它们的词性(parts-of-speech,POS)分类并相应地对它们进行标注.这个过 ...

  8. migrate

    数据类型 引用 # :string, :text, :integer, :float,:decimal, :datetime, :timestamp, :time, :date, # :binary, ...

  9. 用linux搭建ranzhi环境

    一.安装红帽6.5 1.安装时需选择桥接模式: 2.选择自定义,在设置中将镜像文件(ISO)选择进去: 3.安装时选择[桌面]安装(在/etc/inittab文件中,若id=5则为桌面模式,id=3为 ...

  10. var妙用

    var广泛使用其实也有用的.比如在一些不太确定类型的地方 (比如要区分int/uint/long/double的时候),用泛型太牛刀而不用又觉得不灵活的时候,其实是比较推荐var的比如设计某种类的时候 ...