题目:http://poj.org/problem?id=2069

仍是随机地模拟退火,然而却WA了;

看看网上的题解,都是另一种做法——向距离最远的点靠近;

于是也改成那样,竟然真的A了...感觉这个做法的随机因素好像很小?不过似乎也是一种套路。

代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<ctime>
#define eps 1e-17
#define dt 0.997
using namespace std;
typedef double db;
int const xn=;
int n;
db xx[xn],yy[xn],zz[xn],ans,ansx,ansy,ansz;
int rd()
{
int ret=,f=; char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=; ch=getchar();}
while(ch>=''&&ch<='')ret=(ret<<)+(ret<<)+ch-'',ch=getchar();
return f?ret:-ret;
}
db dist(db x,db y,db z,db a,db b,db c){return sqrt((x-a)*(x-a)+(y-b)*(y-b)+(z-c)*(z-c));}
db cal(db x,db y,db z)
{
db ret=;
for(int i=;i<=n;i++)ret=max(ret,dist(x,y,z,xx[i],yy[i],zz[i]));
return ret;
}
void SA()
{
db T=,x=ansx,y=ansy,z=ansz,lst=ans,tx,ty,tz,tmp;
while(T>eps)
{
int id; db ret=,tt;
for(int i=;i<=n;i++)
if((tt=dist(x,y,z,xx[i],yy[i],zz[i]))>ret)ret=tt,id=i;
ans=min(ans,ret);
x+=(xx[id]-x)/ret*T;
y+=(yy[id]-y)/ret*T;
z+=(zz[id]-z)/ret*T;
T*=dt;
}
}
int main()
{
srand(time());
while()
{
n=rd(); if(!n)return ; db sx=,sy=,sz=;
for(int i=;i<=n;i++)
scanf("%lf%lf%lf",&xx[i],&yy[i],&zz[i]),sx+=xx[i],sy+=yy[i],sz+=zz[i];
ansx=sx/n; ansy=sy/n; ansz=sz/n;
ans=cal(ansx,ansy,ansz);
SA();
printf("%.5lf\n",ans);
}
return ;
}

poj 2069 Super Star —— 模拟退火的更多相关文章

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

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

  2. poj 2069 Super Star 模拟退火

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

  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. Unable to lock the administration directory (/var/lib/dpkg/) is another process using it?

    I see pretty much all the answers recommend deleting the lock. I don't recommend doing that as a fir ...

  2. 自己写的通过ADO操作mysql数据库

    #include <iostream> #include <windows.h> #include <atlstr.h> #import "c:\Prog ...

  3. C++虚继承的概念(转)

    http://blog.csdn.net/wangxingbao4227/article/details/6772579 C++中虚拟继承的概念 为了解决从不同途径继承来的同名的数据成员在内存中有不同 ...

  4. [3 Jun 2015 ~ 9 Jun 2015] Deep Learning in arxiv

    arXiv is an e-print service in the fields of physics, mathematics, computer science, quantitative bi ...

  5. python(19)- 列表生成式和生成器表达式练习Ⅰ

    列表表达式 程序一: 常规写法: egg_list=[] for i in range(100): egg_list.append('egg%s' %i) print(egg_list) 列表表达式写 ...

  6. 两种IO模式:Proactor与Reactor模式

    在高性能的I/O设计中,有两个比较著名的模式Reactor和Proactor模式,其中Reactor模式用于同步I/O,而Proactor运用于异步I/O操作. 在比较这两个模式之前,我们首先的搞明白 ...

  7. 【NoSql】Redis实践篇-简单demo实现(一)

    Redis是一个key-value存储系统. Redis的出现,非常大程度补偿了memcached这类key/value存储的不足,在部分场合能够对关系数据库起到非常好的补充作用 Redis是一个ke ...

  8. C++编译错误 2001 1120

    无法解析的外部符号"symbol" 代码引用了链接器无法在库和对象文件中找到的内容(如函数.变量或标签). 该错误信息之后为错误 LNK1120. 可能的原因 : 在将托管库或 W ...

  9. 关于erlang反编译的东西

    在查阅了相关文档,想了解erlang反编译的东西.当然,源码可以打包成可以获取源码的,也可以保护源码的. 在ebin下,如果没有或者找不到源码,可以进行反编译,由beam文件得到erl文件. 可以通过 ...

  10. ubuntu手机识别

    1.sudo gedit /etc/udev/rules.d/51-android.rules 2.将以下内容拷贝保存 SUBSYSTEM=="usb", ATTR{idVendo ...