【模拟退火】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 ...
随机推荐
- C# SuperSocket 消息推送
服务端使用Nuget引用SuperSocket.WebSocket和SuperSocket.Engine 服务器端代码[控制台] using SuperSocket.WebSocket; using ...
- thread线程栈size及局部变量最大可分配size【转】
转自:http://blog.csdn.net/sunny04/article/details/46805261 版权声明:本文为博主原创文章,未经博主允许不得转载. 进程是操作系统的最小资源管理单元 ...
- 在64位linux下编译32位程序
在64位linux下编译32位程序 http://blog.csdn.net/xsckernel/article/details/38045783
- leetcode 343. Integer Break(dp或数学推导)
Given a positive integer n, break it into the sum of at least two positive integers and maximize the ...
- shell 智能获取历史记录功能
vim ~/.inputrc 文件内容: "\e[A": history-search-backward"\e[B": history-search-forwa ...
- Hadoop-MR[会用]MR程序的运行模式
1.简介 现在很少用到使用MR计算框架来实现功能,通常的做法是使用hive等工具辅助完成.但是对于其底层MR的原理还是有必要做一些了解. 2.MR客户端程序实现套路 这一小节总结归纳编写mr客户端程序 ...
- [New learn] 手势
1.简介 我们经常会在设备上查看图片等, 也会经常将图片通过手指的捏合打开来缩小和方法图片.这就是ios中的手势功能在起作用. 那么手势好像也是一种touch事件,那和UIResponder中定义的t ...
- C# 笔记——委托
委托是一个类型安全的对象,它指向程序中另一个以后会被调用的方法(或多个方法).通俗的说,委托是一个可以引用方法的对象,当创建一个委托,也就创建一个引用方法的对象,进而就可以调用那个方法,即委托可以调用 ...
- SRM 638 Div.2
250 给一个字符串 要求从一种形式换成另一形式 class NamingConvention{ private: int a, b, c; public: int d; string toCamel ...
- linux命令(18):chmod命令
1. 命令格式: chmod [-cfvR] [--help] [--version] mode file 2. 命令功能: 用于改变文件或目录的访问权限,用它控制文件或目录的访问权限. 3. 命令参 ...