【POJ】2069.Super Star
题解
求一个最小的半径的球,包括三维平面上所有的点,输出半径
随机移动球心,半径即为距离最远的点,移动的方式是向离的最远的那个点移动一点,之后模拟退火就好
代码
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
//#define ivorysi
#define MAXN 105
#define eps 1e-8
#define pb push_back
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
struct Point {
db x,y,z;
Point(db _x = 0,db _y = 0,db _z = 0) {
x = _x;y = _y;z = _z;
}
}P[35];
int N;
u32 Rand() {
static u32 x = 1736382156;
return x += x << 2 | 1;
}
db Rand_p() {
return (db) (Rand() % 10000) / 10000;
}
inline db o(db x) {return x * x;}
db dist(Point a,Point b) {
return sqrt(o(a.x - b.x) + o(a.y - b.y) + o(a.z - b.z));
}
db get_radius(Point a) {
db res = dist(a,P[1]);
for(int i = 2 ; i <= N ; ++i) res = max(res,dist(P[i],a));
return res;
}
int get_farthest(Point a) {
int r = 1;
for(int i = 2 ; i <= N ; ++i) {
if(dist(a,P[i]) > dist(a,P[r])) r = i;
}
return r;
}
void Solve() {
db delta = 0.99,T = 1000;
db now = get_radius(P[1]),ans = now;
Point s = P[1];
while(T > eps) {
ans = min(ans,now);
int c = get_farthest(s);
db d = dist(P[c],s);
Point t = Point(s.x + (P[c].x - s.x) / d * T,s.y + (P[c].y - s.y) / d * T,s.z + (P[c].z - s.z) / d * T);
db r = get_radius(t);
if(r <= now) {
now = r,s = t;
}
else {
if(exp((now - r) / T) > Rand_p()) {
now = r,s = t;
}
}
T *= delta;
}
printf("%.5f\n",ans);
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
while(scanf("%d",&N) != EOF && N) {
for(int i = 1 ; i <= N ; ++i) {
scanf("%lf%lf%lf",&P[i].x,&P[i].y,&P[i].z);
}
Solve();
}
}
【POJ】2069.Super Star的更多相关文章
- 【POJ】2420 A Star not a Tree?
http://poj.org/problem?id=2420 题意:给n个点,求一个点使得到这个n个点的距离和最短,输出这个最短距离(n<=100) #include <cstdio> ...
- 【POJ】2420 A Star not a Tree?(模拟退火)
题目 传送门:QWQ 分析 军训完状态不好QwQ,做不动难题,于是就学了下模拟退火. 之前一直以为是个非常nb的东西,主要原因可能是差不多省选前我试着学一下但是根本看不懂? 骗分利器,但据说由于调参困 ...
- 【模拟退火】poj2069 Super Star
题意:让你求空间内n个点的最小覆盖球. 模拟退火随机走的时候主要有这几种走法:①随机旋转角度. ②直接不随机,往最远的点的方向走,仅仅在尝试接受解的时候用概率.(最小圆/球覆盖时常用) ③往所有点的方 ...
- 【POJ】1704 Georgia and Bob(Staircase Nim)
Description Georgia and Bob decide to play a self-invented game. They draw a row of grids on paper, ...
- 【POJ】1067 取石子游戏(博弈论)
Description 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两堆中同时取走相同数量的石子.最后 ...
- POJ 2069 Super Star(计算几何の最小球包含+模拟退火)
Description During a voyage of the starship Hakodate-maru (see Problem 1406), researchers found stra ...
- 【BZOJ】【1986】【USACO 2004 Dec】/【POJ】【2373】划区灌溉
DP/单调队列优化 首先不考虑奶牛的喜欢区间,dp方程当然是比较显然的:$ f[i]=min(f[k])+1,i-2*b \leq k \leq i-2*a $ 当然这里的$i$和$k$都是偶数啦~ ...
- 【POJ】【2104】区间第K大
可持久化线段树 可持久化线段树是一种神奇的数据结构,它跟我们原来常用的线段树不同,它每次更新是不更改原来数据的,而是新开节点,维护它的历史版本,实现“可持久化”.(当然视情况也会有需要修改的时候) 可 ...
- 【POJ】1222 EXTENDED LIGHTS OUT
[算法]高斯消元 [题解] 高斯消元经典题型:异或方程组 poj 1222 高斯消元详解 异或相当于相加后mod2 异或方程组就是把加减消元全部改为异或. 异或性质:00 11为假,01 10为真.与 ...
随机推荐
- python中高阶函数与装饰器
高阶函数的定义:传入参数有函数名或者返回值有内置函数名的函数. 最简单的高阶函数: def add(x, y, f): return f(x) + f(y) add(-5, 6, abs) 常用 ...
- 用Python来进行词频统计
# 把语料中的单词全部抽取出来, 转成小写, 并且去除单词中间的特殊符号 def words(text): return re.findall('[a-z]+', text.lower()) def ...
- Redis学习六:Redis的持久化-AOF
AOF(Append Only File) 一.是什么 以日志的形式来记录每个写操作,将Redis执行过的所有写指令记录下来(读操作不记录),只许追加文件但不可以改写文件,redis启动之初会读取该文 ...
- R7—左右内全连接详解
在SQL查询中,经常会用到左连接.右连接.内连接.全连接,那么在R中如何实现这些功能,今天来讲一讲! SQL回顾 原理 # 连接可分为以下几类: 内连接.(典型的连接运算,使用像 = 或 ...
- 51nod 小Z的trie(Trie+广义SAM)
[题目链接] http://www.51nod.com/contest/problem.html#!problemId=1647 [题意] 给定一个n个字符串的Trie,每次询问一个字符串在Trie上 ...
- 七牛云 上传图片 https 修改Nginx 注意事项
仅在这记录下,今天的事情. 问题出自于Nginx 设置http 强制跳转 https设置 1.上午,出于某些需求,我将服务器Nginx 设置http 强行跳转 https server { liste ...
- POJ 2485 Highways( 最小生成树)
题目链接 Description The islandnation of Flatopia is perfectly flat. Unfortunately, Flatopia has no publ ...
- [转]google gflags 库完全使用
简单介绍 gflags 是 google 开源的用于处理命令行参数的项目. 安装编译 项目主页:gflags ➜ ~ git clone https://github.com/gflags/gflag ...
- perl6 Net::HTTP 发送任意 url 请求例子
只做个笔记, 用 HTTP::UserAgent 的话, url 中有特殊点的符号会请求不了, 用 Net::HTTP 能很好的发送请求. use Net::HTTP::GET; my $url = ...
- Count 1 in Binary
Count how many 1 in binary representation of a 32-bit integer. Example Given 32, return 1 Given 5, r ...