poj 2069 Super Star 模拟退火
题目大意:
给定三位空间上的n(\(n \leq 30\))个点,求最小的球覆盖掉所有的点.
题解:
貌似我们可以用类似于二维平面中的随机增量法瞎搞一下
但是我不会怎么搞
所以我们模拟退火就好了啊QAQ
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
inline void read(int &x){
x=0;char ch;bool flag = false;
while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
inline int cat_max(const int &a,const int &b){return a>b ? a:b;}
inline int cat_min(const int &a,const int &b){return a<b ? a:b;}
const int maxn = 45;
const double eps = 1e-15;
const double det = 0.99;
struct Point{
double x,y,z;
Point(const double &a=0,const double &b=0,const double &c=0){
x=a;y=b;z=c;
}
};
inline double dis(const Point &a,const Point &b){
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z));
}
int n;double ans = 1e100;
Point p[maxn];
inline double f(const Point &x){
double ret = 0;
for(int i=1;i<=n;++i) ret = max(ret,dis(x,p[i]));
if(ret < ans) ans = ret;
return ret;
}
inline double ran(){
return (rand() % 1000 + 1)/1000.0;
}
Point nw;
int main(){
srand(2333);
while(1){
read(n);if(n == 0) break;
nw.x = nw.y = nw.z = 0;
ans = 1e100;
for(int i=1;i<=n;++i){
scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].z);
}
double T = 100.0,x;
double dist;int pos;
while(T > eps){
dist = 0.0;
for(int i=1;i<=n;++i){
if(dist < dis(nw,p[i])){
pos = i;dist = dis(nw,p[i]);
}
}
Point nx(
nw.x+(p[pos].x-nw.x)/dist*T,
nw.y+(p[pos].y-nw.y)/dist*T,
nw.z+(p[pos].z-nw.z)/dist*T
);
x = f(nw) - f(nx);
if(x > 0 || exp(x/T) > ran()) nw = nx;
T *= det;
}
printf("%.5lf\n",ans);
}
getchar();getchar();
return 0;
}
poj 2069 Super Star 模拟退火的更多相关文章
- 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(计算几何の最小球包含+模拟退火)
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 题意:求一个半径最小的球,使得它可以包围住所有点. 模拟退火,圆心每次都去找最远那个点,这样两点之间的距离就是半径,那么接下来移 ...
随机推荐
- Myecplise Tomcat 启动很慢
今天突然遇到一个问题,tomcat在Myecplse启动非常慢,直接用tomcat自带的start.bat启动很快,如果通过Myeclipse启动会发现项目一直在实例化,最后发现是因为加了断点调试,断 ...
- 【BZOJ3060】[Poi2012]Tour de Byteotia 并查集
[BZOJ3060][Poi2012]Tour de Byteotia Description 给定一个n个点m条边的无向图,问最少删掉多少条边能使得编号小于等于k的点都不在环上. Input ...
- 小程序发起post请求回调成功没有数据
get请求时为 header:{ "content-type":'application/json' },POST 请求会将data的值放在Request Payload里面,而不 ...
- 3.写一个hello world页面
经过1和2的学习,现在已经可以正常启动Django了,这一节说怎么写一个hello world页面,所有的环境基础就是1和2中搭建的 1.在app模块中添加页面 具体为 hello_django\he ...
- linux c编程:进程环境
一 进程终止: ⼀个进程可以登记若⼲个(具体⾃⼰验证⼀下)个函数,这些函数由exit⾃动调⽤,这些函数被称为终⽌处理函数, atexit函数可以登记这些函数. exit调⽤终⽌处理函数的顺序和atex ...
- 编程算法 - 最好牛线(Best Cow Line) 代码(C)
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u012515223/article/details/37909933 最好牛线(Best Cow L ...
- 3django url name详解
打开urls.py from django.conf.urls import url from django.contrib import admin from calc import views a ...
- IOS UI Frame 相对位置调整 与优化方法 Height Width X Y 调整
不使用xib ,纯代码开发的过程中,动态UI 需要改对象的大小位置 反复使用CGRectMake 去 setFrame 非常低效耗时,而且 牵一发动全身. 以下整理出几个方法,方便动态布局 1.s ...
- iOS 8以后 定位手动授权问题
ios8以后 都是手动授权定位权限 不过不处理这块 在ios8以后的系统就会默认永不授权 即关闭了定位权限 处理办法如下 .导入框架头文件 #import <CoreLocation/CoreL ...
- maven导入项目时,缺少部分source folder
今天导入公司的maven项目时,少了一些source folder,运行启动正常,但是页面打不开,找不到对应的目录文件,使用maven更新项目,重启编辑器也无效. 问题描述如图所示,缺少了图中的2个目 ...