poj 2069 Super Star——模拟退火(收敛)
题目:http://poj.org/problem?id=2069
不是随机走,而是每次向最远的点逼近。而且也不是向该点逼近随意值,而是按那个比例;这样就总是接受,但答案还是要取min更新。
不知那个比例是怎么算。不过如果直接随机走或者向那个方向随机走的话,就过不了。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<ctime>
#include<cmath>
#include<cstdlib>
#define db double
#define ll long long
using namespace std;
const int N=;
const db dc=0.997,eps=1e-,INF=;
int n;
db nx[N],ny[N],nz[N],px,py,pz,ans;
db dis(db x0,db y0,db z0,db x1,db y1,db z1)
{
return sqrt((x0-x1)*(x0-x1)+(y0-y1)*(y0-y1)+(z0-z1)*(z0-z1));
}
void SA(db T)
{
db x=px,y=py,z=pz,pr=ans;int id;
while(T>eps)
{
db d=;
for(int i=;i<=n;i++)
{
db tmp=dis(x,y,z,nx[i],ny[i],nz[i]);
if(tmp>d)d=tmp,id=i;
}
ans=min(ans,d);
x=x+(nx[id]-x)/d*T;y=y+(ny[id]-y)/d*T;z=z+(nz[id]-z)/d*T;
T*=dc;
}
}
int main()
{
srand(time());
while()
{
scanf("%d",&n);if(!n)return ;
for(int i=;i<=n;i++)
scanf("%lf%lf%lf",&nx[i],&ny[i],&nz[i]),px+=nx[i],py+=ny[i],pz+=nz[i];
px/=n;py/=n;pz/=n;
for(int i=;i<=n;i++)
ans=max(ans,dis(px,py,pz,nx[i],ny[i],nz[i]));
SA();
printf("%.5lf\n",ans);
}
return ;
}
poj 2069 Super Star——模拟退火(收敛)的更多相关文章
- poj 2069 Super Star —— 模拟退火
题目:http://poj.org/problem?id=2069 仍是随机地模拟退火,然而却WA了: 看看网上的题解,都是另一种做法——向距离最远的点靠近: 于是也改成那样,竟然真的A了...感觉这 ...
- poj 2069 Super Star 模拟退火
题目大意: 给定三位空间上的n(\(n \leq 30\))个点,求最小的球覆盖掉所有的点. 题解: 貌似我们可以用类似于二维平面中的随机增量法瞎搞一下 但是我不会怎么搞 所以我们模拟退火就好了啊QA ...
- 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 题意:求一个半径最小的球,使得它可以包围住所有点. 模拟退火,圆心每次都去找最远那个点,这样两点之间的距离就是半径,那么接下来移 ...
随机推荐
- unbuntu16.04上python开发环境搭建建议
unbuntu16.04上python开发环境搭建建议 2017-12-20 10:39:27 推荐列表: pycharm: 可以自行破解,但是不推荐,另外也不稳定 pydev+eclipse: ...
- 完好用户体验: 活用window.location与window.open解决页面跳转问题
原文地址: JavaScript Redirects and window.open原文日期: 2014年08月27日翻译日期: 2014年08月31日翻译人员: 铁锚 (译者注: 本文解决的是按 C ...
- Jenkins--Run shell command in jenkins as root user?
You need to modify the permission for jenkins user so that you can run the shell commands. You can i ...
- 检查Nginx的配置,重载配置和重启的方法
Nginx 安装后只有一个程序文件,本身并不提供各种管理程序,它是使用参数和系统信号机制对 Nginx 进程本身进行控制的. Nginx 的参数包括有如下几个: 可以这样使用 /usr/local/n ...
- PowerBuilder -- 保存图片
String ls_path, ls_file_name, ls_filter, ls_errInt li_ret, li_loop, li_i, li_file, li_bytesLong ll_f ...
- Struts2 ModelDriven接口使用
用户在做http请求时一般都有两种方式:get和post方式.get方式用来获取查询相关信息,既向服务器获得信息,而post方式用来更新信息既向服务器提交数据.通常情况下,用get方式向服务器获取信息 ...
- 一步一步学ios UITextView(多行文本框)控件的用法详解(五5.8)
本文转载至 http://wuchaorang.2008.blog.163.com/blog/static/48891852201232014813990/ 1.创建并初始化 创建UIText ...
- 【BZOJ3956】Count 主席树+单调栈
[BZOJ3956]Count Description Input Output Sample Input 3 2 0 2 1 2 1 1 1 3 Sample Output 0 3 HINT M,N ...
- EasyPlayerPro windows播放器本地音频播放音量控制实现
背景描述 作为一个播放器, 除了能播放视频和声音外,音量控制是绝对不能缺少的功能; 本文在音视频播放的基础上,增加对音量的控制: 实现流程 调用mixerGetDevCaps获取音频输出设备列表; 打 ...
- android菜鸟学习笔记16----Android项目打包安装过程(Run as Android Application)
右击项目名称,Run as Android Appication之后,Android项目打包安装过程: 1.打包生成.apk文件: 1)把源码中的.java文件编译生成.class文件 2)将所有的. ...