【模拟退火】poj2069 Super Star
题意:让你求空间内n个点的最小覆盖球。
模拟退火随机走的时候主要有这几种走法:①随机旋转角度。
②直接不随机,往最远的点的方向走,仅仅在尝试接受解的时候用概率。(最小圆/球覆盖时常用)
③往所有点的方向的总和走,仅仅在尝试接受解的时候用概率。(费马点时常用)
像这题,我用第一种最暴力的随机,死活过不了……
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;
const double EPS=0.00000001;
const double PI=acos(-1.0);
struct Point{
double x,y,z;
Point(const double &x,const double &y,const double &z){
this->x=x;
this->y=y;
this->z=z;
}
Point(){}
void read(){
scanf("%lf%lf%lf",&x,&y,&z);
}
double length(){
return sqrt(x*x+y*y+z*z);
}
}a[35],p,allp;
double ans,allans;
int n;
typedef Point Vector;
Vector operator - (const Point &a,const Point &b){
return Vector(a.x-b.x,a.y-b.y,a.z-b.z);
}
Vector operator + (const Vector &a,const Vector &b){
return Vector(a.x+b.x,a.y+b.y,a.z+b.z);
}
Vector operator * (const double &K,const Vector &v){
return Vector(K*v.x,K*v.y,K*v.z);
}
double calc(Point p){
double res=0.0;
for(int i=1;i<=n;++i){
res=max(res,(a[i]-p).length());
}
return res;
}
//double ran(){
// int fm=rand()%10000+1;
// return ((rand()&1) ? -1.0 : 1.0)*((double)(rand()%(fm+1))/(double)fm);
//}
Vector unit(Vector v){
double l=v.length();
return Vector(v.x/l,v.y/l,v.z/l);
}
int main(){
srand(233);
//freopen("poj2069.in","r",stdin);
while(1){
scanf("%d",&n);
if(!n){
return 0;
}
allans=100000.0;
for(int i=1;i<=n;++i){
a[i].read();
}
// for(int j=1;j<=n;++j){
p=a[1];
ans=calc(p);
double T=sqrt(20000.0);
while(T>EPS){
double bestnow=100000.0;
Point besttp;
// for(int i=1;i<=30;++i){
// double rad=(double)(rand()%10000+1)/10000.0*2.0*PI;
int to;
double far=0.0;
for(int k=1;k<=n;++k){
double tmp=(a[k]-p).length();
if(tmp>far){
far=tmp;
to=k;
}
}
Point tp=p+T*unit(a[to]-p);
double now=calc(tp);
if(now<bestnow){
bestnow=now;
besttp=tp;
}
// }
if(bestnow-100000.0<-EPS && (bestnow<ans || exp((ans-bestnow)/T)*10000.0>(double)(rand()%10000))){
ans=bestnow;
p=besttp;
}
T*=0.99;
}
if(ans<allans){
allans=ans;
// allp=p;
}
// }
printf("%.5lf\n",fabs(allans));
}
return 0;
}
【模拟退火】poj2069 Super Star的更多相关文章
- [POJ2069]Super Star(模拟退火)
题目链接:http://poj.org/problem?id=2069 题意:求一个半径最小的球,使得它可以包围住所有点. 模拟退火,圆心每次都去找最远那个点,这样两点之间的距离就是半径,那么接下来移 ...
- POJ 2069 Super Star(计算几何の最小球包含+模拟退火)
Description During a voyage of the starship Hakodate-maru (see Problem 1406), researchers found stra ...
- Super Star(最小球覆盖)
Super Star http://poj.org/problem?id=2069 Time Limit: 1000MS Memory Limit: 65536K Total Submission ...
- POJ2069:Super Star
我对模拟退火的理解:https://www.cnblogs.com/AKMer/p/9580982.html 我对爬山的理解:https://www.cnblogs.com/AKMer/p/95552 ...
- poj 2069 Super Star 模拟退火
题目大意: 给定三位空间上的n(\(n \leq 30\))个点,求最小的球覆盖掉所有的点. 题解: 貌似我们可以用类似于二维平面中的随机增量法瞎搞一下 但是我不会怎么搞 所以我们模拟退火就好了啊QA ...
- 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
模拟退火. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm& ...
- 【POJ】2069.Super Star
题解 求一个最小的半径的球,包括三维平面上所有的点,输出半径 随机移动球心,半径即为距离最远的点,移动的方式是向离的最远的那个点移动一点,之后模拟退火就好 代码 #include <iostre ...
随机推荐
- Spring 路由地址的基本使用
1.下面是spring的使用基本框架连接 https://www.cnblogs.com/HD/p/4103239.html
- poj 2762 tarjan缩点+拓扑序
2013-09-08 10:00 var m, n :longint; t :longint; f, last :..] of longint; pre, other :..] of longint; ...
- Python 关于拷贝(copy)汇总(列表拷贝 // 字典拷贝 // 自定义对象拷贝)
1.列表拷贝 引用是指保存的值为对象的地址.在 Python 语言中,一个变量保存的值除了基本类型保存的是值外,其它都是引用,因此对于它们的使用就需要小心一些.下面举个例子: 问题描述:已知一个列表, ...
- 常见网络命令之traceroute命令一起其他常用命令
备注:任何命令+/?就可以显示命令帮助,比如:ipconfig /?. traceroute命令 traceroute是UNIX系统中的名字,用来跟踪一个分组从源点到终点的路径.在Windows系统中 ...
- C++学习之路(六):实现一个String类
直接贴代码吧,这段时间准备面试也正好练习了一下. class String { public: String(const char *str = ""); ~String(void ...
- 嵌入式 uboot引导kernel,kernel引导fs【转】
转自:http://www.cnblogs.com/lidabo/p/5383934.html#3639633 1.uboot引导kernel: u-boot中有个bootm命令,它可以引导内存中的应 ...
- VPS性能测试(2):内存大小、交换空间、高速缓存、实际使用内存
1.要想查看购买的VPS主机的内存信息,执行:cat /proc/meminfo,主要是看内存大小.交换空间.高速缓存 2.VPS主机实际使用内存大小.Linux管理内存的机制是这样的:无论物理内存有 ...
- 【LabVIEW技巧】策略模式
前言 在之前的文章提到了如何学习OOP以及对应的简单工厂模式,由于时间比较长,我们先回顾一下原有内容,然后继续了解新的模式. 为什么学习OOP 在测控系统的软件开发过程中,LabVIEW工程师一直认为 ...
- LeetCode解题报告—— Unique Binary Search Trees & Binary Tree Level Order Traversal & Binary Tree Zigzag Level Order Traversal
1. Unique Binary Search Trees Given n, how many structurally unique BST's (binary search trees) that ...
- hdu 2044-2050 递推专题
总结一下做递推题的经验,一般都开成long long (别看项数少,随便就超了) 一般从第 i 项开始推其与前面项的关系(动态规划也是这样),而不是从第i 项推其与后面的项的关系. hdu2044:h ...