题意:让你求空间内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的更多相关文章

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

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

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

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

  3. Super Star(最小球覆盖)

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

  4. POJ2069:Super Star

    我对模拟退火的理解:https://www.cnblogs.com/AKMer/p/9580982.html 我对爬山的理解:https://www.cnblogs.com/AKMer/p/95552 ...

  5. poj 2069 Super Star 模拟退火

    题目大意: 给定三位空间上的n(\(n \leq 30\))个点,求最小的球覆盖掉所有的点. 题解: 貌似我们可以用类似于二维平面中的随机增量法瞎搞一下 但是我不会怎么搞 所以我们模拟退火就好了啊QA ...

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

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

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

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

  8. POJ 2069 Super Star

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

  9. 【POJ】2069.Super Star

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

随机推荐

  1. bzoj 3450 DP

    首先我们设len[i]表示前i位,从第i位往前拓展,期望有多少个'o',那么比较容易的转移 len[i]=len[i-1]+1 s[i]='o' len[i]=0 s[i]='x' len[i]=(l ...

  2. 前端—css

    css css概述 CSS是Cascading Style Sheets的简称,中文称为层叠样式表,用来控制网页数据的表现,可以使网页的表现与数据内容分离. 一.css的四种引入方式: 1.行内式   ...

  3. Laravel 5.2 数据库迁移和数据填充

    一.数据库迁移 Laravel 的数据库迁移提供了对数据库.表.字段.索引的一系列相关操作.下面以创建友情链接表为例. 1. 创建迁移 使用 Artisan 命令  php artisan make: ...

  4. 【bzoj4530】大融合(LCT的子树维护)

    LCT维护子树并没有想象中的那么难,在这里只是复习下. (其他的维护子树的题目,可见:“共价大爷游长沙”) 只要记录下虚边连接的信息就好了. #include<bits/stdc++.h> ...

  5. webapi-1 给现有MVC 项目添加 WebAPI

    1. 增加一个WebApi Controller, VS 会自动添加相关的引用,主要有System.Web.Http,System.Web.Http.WebHost,System.Net.Http 2 ...

  6. Python——turtle生成图片保存

    代码示例如下: from Tkinter import * from turtle import * import turtle forward(100) ts = turtle.getscreen( ...

  7. Python在线教程

    Python 3.x的 http://www.ziqiangxuetang.com/python3/python3-stdlib.html 廖雪峰的官方网站 http://www.liaoxuefen ...

  8. EL表达式使用时出现NumberFormatException异常

    从后端数据库取出书本集合,然后循环输出到前端表格: <c:forEach items="${bookManagedBean.bookList}" var="book ...

  9. beatfullsoup

    阅读目录 一 介绍 二 基本使用 三 遍历文档树 四 搜索文档树 五 修改文档树 六 总结 一 介绍 Beautiful Soup 是一个可以从HTML或XML文件中提取数据的Python库.它能够通 ...

  10. hdu 1664(数论+同余搜索+记录路径)

    Different Digits Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...