poj 2069 Super Star 模拟退火
题目大意:
给定三位空间上的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 模拟退火的更多相关文章
- poj 2069 Super Star —— 模拟退火
题目:http://poj.org/problem?id=2069 仍是随机地模拟退火,然而却WA了: 看看网上的题解,都是另一种做法——向距离最远的点靠近: 于是也改成那样,竟然真的A了...感觉这 ...
- poj 2069 Super Star——模拟退火(收敛)
题目:http://poj.org/problem?id=2069 不是随机走,而是每次向最远的点逼近.而且也不是向该点逼近随意值,而是按那个比例:这样就总是接受,但答案还是要取min更新. 不知那个 ...
- POJ 2069 Super Star(计算几何の最小球包含+模拟退火)
Description During a voyage of the starship Hakodate-maru (see Problem 1406), researchers found stra ...
- POJ 2069 Super Star
模拟退火. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm& ...
- 【POJ】2069.Super Star
题解 求一个最小的半径的球,包括三维平面上所有的点,输出半径 随机移动球心,半径即为距离最远的点,移动的方式是向离的最远的那个点移动一点,之后模拟退火就好 代码 #include <iostre ...
- POJ 2069 模拟退火算法
Super Star Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6422 Accepted: 1591 Spec ...
- Super Star(最小球覆盖)
Super Star http://poj.org/problem?id=2069 Time Limit: 1000MS Memory Limit: 65536K Total Submission ...
- 三分 POJ 2420 A Star not a Tree?
题目传送门 /* 题意:求费马点 三分:对x轴和y轴求极值,使到每个点的距离和最小 */ #include <cstdio> #include <algorithm> #inc ...
- [POJ2069]Super Star(模拟退火)
题目链接:http://poj.org/problem?id=2069 题意:求一个半径最小的球,使得它可以包围住所有点. 模拟退火,圆心每次都去找最远那个点,这样两点之间的距离就是半径,那么接下来移 ...
随机推荐
- Pairs of Integers
Pairs of Integers You are to find all pairs of integers such that their sum is equal to the given in ...
- php建立一个空类: stdClass
$pick = new stdClass; $pick->type = 'full'; ;
- Django 之 admin组件使用&源码解析
admin组件使用 Django 提供了基于 web 的管理工具. Django 自动管理工具是 django.contrib 的一部分.可以在项目的 settings.py 中的 INSTALLED ...
- [转载]Java集合容器简介
Java集合容器主要有以下几类: 1,内置容器:数组 2,list容器:Vetor,Stack,ArrayList,LinkedList, CopyOnWriteArrayList(1.5),Attr ...
- activiti 基础搭建
首先在eclipse内添加activiti的插件,https://blog.csdn.net/qq_22701869/article/details/79537971 1.创建一个maven的java ...
- 图片oom问题
1.什么是OOM? 程序申请内存过大,虚拟机无法满足我们,然后自杀了.这个现象通常出现在大图片的APP开发,或者需要用到很多图片的时候.通俗来讲就是我们的APP需要申请一块内存来存放图片的时候,系统认 ...
- DEV开发之界面皮肤
最终效果:正文本人的环境是 VS2013+DEV 13.21.第一步,新建项目,(忽略)???2.修改Form1.cs的基类,Form修改为DevExpress.XtraBars.Ribbon.Rib ...
- P4965 薇尔莉特的打字机
题目 P4965 薇尔莉特的打字机 快到十二点了正在颓废突然发现了一道好题 虽然毒瘤,但确实是容斥原理的好题啊,做法也特别巧妙(标程 思路 题目大意(怕自己突然忘) n个初始字符,m个操作(加入或删除 ...
- import与import static
import ......className (静态导入) 功能: 导入一个类 import static ......className.* 功能:导入这个类里的静态方法,是JDK1.5中的新特性, ...
- tkinter模块中常用的参数
以下内容来自于:http://www.cnblogs.com/aland-1415/p/6849193.html(个别内容掺入了自己的重新整理) cnf={}与**kw: cnf={}这是一个默认参数 ...