【模拟退火】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 ...
随机推荐
- HDU 1114 Piggy-Bank (dp)
题目链接 Problem Description Before ACM can do anything, a budget must be prepared and the necessary fin ...
- centos7 多版本python并存问题
新的阿里云服务器,本身装有python2.7,但是项目需要python3,于是只能再装一个python3.6 参考文章:https://www.cnblogs.com/johnny1024/p/844 ...
- tornado简单使用
这篇适用于快速上手想了解更深:http://www.tornadoweb.cn/ https://tornado-zh.readthedocs.io/zh/latest/ Tornado 是 Fr ...
- python基础===修改属性的值
可以以三种不同的方式修改属性的值:直接通过实例进行修改:通过方法进行设置:通过方法进行递增(增加特定的值).下面依次介绍这些方法. class Car(): def __init__(self, ma ...
- 64_k1
KoboDeluxe-0.5.1-22.fc26.x86_64.rpm 13-Feb-2017 22:11 1626454 k3b-17.04.1-1.fc26.x86_64.rpm 25-May-2 ...
- Java中volatile修饰符,不稳定标记的用法笔记
今天学java特性时,发现了volatile修饰符,这个修饰符修饰的变量告诉java编译器忽略优化机制,这样的优势是: java优化后,寄存器会缓存内存里的变量,另一个线程修改这个变量的内存时,不会同 ...
- C++内存管理(转)
C++内存管理比较好的文章,参考链接如下: C++内存管理
- C++中string类的方法
C++ string类的方法 具体每个方法怎么使用,可以参考相应的链接. 总的链接为http://www.cplusplus.com/reference/string/string/(C++参考文档) ...
- JWT认证不通过导致不能访问视图的解决方案
在做商城项目的购物车模块时,发现了一个问题. 需求:当用户登录时,添加商品到购物车的数据保存在redis.当用户未登录时,添加商品到购物车的数据保存在cookies.两个功能都写在一个视图里面.以JW ...
- django-1366, "Incorrect string value: '\\xE6\\x88\\x9A\\xE4\\xBC\\x9F...'
今天把之前的一些代码转移到另外一台电脑的时候, python manage.py syncdb 的时候报了 (1366, "Incorrect string value: '\\xE6\\x ...