题目: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. springMVC前后端分离开发模式下支持跨域请求

    1.web.xml中添加cors规则支持(请修改包名) <filter> <filter-name>cors</filter-name> <filter-cl ...

  2. [Algorithm] Write a Depth First Search Algorithm for Graphs in JavaScript

    Depth first search is a graph search algorithm that starts at one node and uses recursion to travel ...

  3. django 实现下载功能

    from django.http import FileResponse def download(request): if..... file=open([path],'rb') response= ...

  4. C 标准库 - <limits.h>

    C 标准库 - <limits.h> 简介 limits.h 头文件决定了各种变量类型的各种属性.定义在该头文件中的宏限制了各种变量类型(比如 char.int 和 long)的值. 这些 ...

  5. 【iOS】UIWebView的HTML5扩展之canvas篇

    先前公布大那个所谓的"HTML5"扩展严格说来还算不是"HTML5".曲曲几行JS代码就自诩为HTML5扩展多少有些标题党的嫌疑. 而相比之下,本篇的主题can ...

  6. Sql语言复习

    一.创建数据库 创建和打开数据库 注意一点:在新建数据库的时候,一般放置数据文件与日志文件的位置,需要提前建立文件夹,不然会报错. 一般主数据文件,我们以.mdf结尾,次数据文件用.ndf结尾.对于日 ...

  7. java多个文件压缩下载

    public static void zipFiles(File[] srcfile,ServletOutputStream sos){ byte[] buf=new byte[1024]; try ...

  8. http 错误代码一览表

    http协议一些常见的状态码为: 1xx(临时响应) 表示临时响应并需要请求者继续执行操作的状态代码. 代码 说明 100 (继续) 请求者应当继续提出请求. 服务器返回此代码表示已收到请求的第一部分 ...

  9. 修改mysql数据库 密码

    将密码改成123456 update mysql.user set authentication_string=password('123456') where user='root' and Hos ...

  10. Jenkins 搭建

    持续集成(CI continuous integration) 可以做什么? 自动构建.定时触发,或由某个事件触发.比如可以做 daily build,或每次代码提交时触发.这样可以最早发现代码编译和 ...