[POJ2069]Super Star(模拟退火)
题目链接:http://poj.org/problem?id=2069
题意:求一个半径最小的球,使得它可以包围住所有点。
模拟退火,圆心每次都去找最远那个点,这样两点之间的距离就是半径,那么接下来移动的方向肯定就是朝着这个最远点移动,保证比例相同且在球内的情况下移动。
不看题解想不到,这个东西有点难啊。。。
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath>
using namespace std; typedef struct P {
double x, y, z;
}P;
const double inf = 1e90;
const double eps = 1e-;
const double delta = 0.98;
const int maxn = ;
P p[maxn];
int n; double dist(P a, P b) {
double p = a.x - b.x;
double q = a.y - b.y;
double r = a.z - b.z;
return sqrt(p*p+q*q+r*r);
} int main() {
// freopen("in", "r", stdin);
while(~scanf("%d", &n) && n) {
for(int i = ; i < n; i++) {
scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].z);
}
double t = ;
double ret = inf;
P pos = {, , };
while(t > eps) {
int k = ;
for(int i = ; i < n; i++) {
if(dist(pos, p[i]) > dist(pos, p[k])) {
k = i;
}
}
double d = dist(pos, p[k]);
ret = min(ret, d);
pos.x += (p[k].x - pos.x) / d * t;
pos.y += (p[k].y - pos.y) / d * t;
pos.z += (p[k].z - pos.z) / d * t;
t *= delta;
}
printf("%.5lf\n", ret);
}
return ;
}
[POJ2069]Super Star(模拟退火)的更多相关文章
- 【模拟退火】poj2069 Super Star
题意:让你求空间内n个点的最小覆盖球. 模拟退火随机走的时候主要有这几种走法:①随机旋转角度. ②直接不随机,往最远的点的方向走,仅仅在尝试接受解的时候用概率.(最小圆/球覆盖时常用) ③往所有点的方 ...
- 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(计算几何の最小球包含+模拟退火)
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
模拟退火. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm& ...
- 【POJ】2069.Super Star
题解 求一个最小的半径的球,包括三维平面上所有的点,输出半径 随机移动球心,半径即为距离最远的点,移动的方式是向离的最远的那个点移动一点,之后模拟退火就好 代码 #include <iostre ...
随机推荐
- spark shell
启动spark-shell客户端 启动集群模式 本机为master节点 export MASTER=spark://`hostname`:7077bin/spark-shell 或者 bin/spar ...
- 移动Web开发调研
背景 在移动互联网浪潮下,移动设备普及,对配置需要考虑移动端设备可访问性.Web作为最贴近用户的配置手段,面向从PC端传统页面,向移动端页面的转型. 概念 PC Web: 面向传统PC电脑的浏览器开发 ...
- Java网络编程之流——流、过滤器、阅读器和书写器
Java的I/O建立于流(Stream)之上.输入流读取数据:输出流写入数据.所有的输出流都有相同的基本方法来写入数据,所有输入流也使用相同的基本方法来读取数据.在创建流之后,你通常可以忽略在读写时的 ...
- git安装及命令使用和github网站
最近参与别人的github项目时,学习了git的使用,首先需要在https://github.com/网站上注册账号和邮箱,然后fork一个开源项目,然后下载目前Windows下最新版本的git,下载 ...
- 浅谈在静态页面上使用动态参数,会造成spider多次和重复抓取的解决方案
原因: 早期由于搜索引擎蜘蛛的不完善,蜘蛛在爬行动态的url的时候很容易由于网站程序的不合理等原因造成蜘蛛迷路死循环. 所以蜘蛛为了避免之前现象就不读取动态的url,特别是带?的url 解决方案: 1 ...
- 夺命雷公狗-----React---16--事件操作事件
<!DOCTYPE> <html> <head> <meta charset="utf-8"> <title></ ...
- 解决jquery mobile的header和footer在点击屏幕的时候消失的办法
给header和footer添加 data-position="fixed" 和 data-tap-toggle="false"即可,代码如下: <div ...
- mysql中使用 where 1=1和 0=1 的作用
操作mysql的时候,经常使用where语句进行查询.当where语句不存在的时候,经常在后面加一个where 1=1 where 1=1; 这个条件始终为True,在不定数量查询条件情况下,1=1可 ...
- svn小设置
由于每次提交代码或者更新代码都需要输入密码,太不方便,今天请教了高手设置一下svn,问题解决... 流程如下 TortoiseSVN --> Settings --> Network ...
- Infinite loop when using cookieless session ID on Azure
If you use cookieless session ID and deploy them on Azure, you might get infinite loop when you quer ...