题解

求一个最小的半径的球,包括三维平面上所有的点,输出半径

随机移动球心,半径即为距离最远的点,移动的方式是向离的最远的那个点移动一点,之后模拟退火就好

代码

#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的更多相关文章

  1. 【POJ】2420 A Star not a Tree?

    http://poj.org/problem?id=2420 题意:给n个点,求一个点使得到这个n个点的距离和最短,输出这个最短距离(n<=100) #include <cstdio> ...

  2. 【POJ】2420 A Star not a Tree?(模拟退火)

    题目 传送门:QWQ 分析 军训完状态不好QwQ,做不动难题,于是就学了下模拟退火. 之前一直以为是个非常nb的东西,主要原因可能是差不多省选前我试着学一下但是根本看不懂? 骗分利器,但据说由于调参困 ...

  3. 【模拟退火】poj2069 Super Star

    题意:让你求空间内n个点的最小覆盖球. 模拟退火随机走的时候主要有这几种走法:①随机旋转角度. ②直接不随机,往最远的点的方向走,仅仅在尝试接受解的时候用概率.(最小圆/球覆盖时常用) ③往所有点的方 ...

  4. 【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, ...

  5. 【POJ】1067 取石子游戏(博弈论)

    Description 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两堆中同时取走相同数量的石子.最后 ...

  6. POJ 2069 Super Star(计算几何の最小球包含+模拟退火)

    Description During a voyage of the starship Hakodate-maru (see Problem 1406), researchers found stra ...

  7. 【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$都是偶数啦~ ...

  8. 【POJ】【2104】区间第K大

    可持久化线段树 可持久化线段树是一种神奇的数据结构,它跟我们原来常用的线段树不同,它每次更新是不更改原来数据的,而是新开节点,维护它的历史版本,实现“可持久化”.(当然视情况也会有需要修改的时候) 可 ...

  9. 【POJ】1222 EXTENDED LIGHTS OUT

    [算法]高斯消元 [题解] 高斯消元经典题型:异或方程组 poj 1222 高斯消元详解 异或相当于相加后mod2 异或方程组就是把加减消元全部改为异或. 异或性质:00 11为假,01 10为真.与 ...

随机推荐

  1. html5页面头部

    <base href="/bulid/"/> <meta charset="UTF-8"/> <meta http-equiv=& ...

  2. Broker流量均衡 prefer reassign

    0.均衡流量的步骤 现在的kafka集群,只要遇到过weibo_common_act2 topic的节点在ZK中丢失,就要prefer一次流量,否则不均匀. 总结均衡流量的一般步骤: 通过hpm查询b ...

  3. 视音频数据处理入门:H.264视频码流解析

    ===================================================== 视音频数据处理入门系列文章: 视音频数据处理入门:RGB.YUV像素数据处理 视音频数据处理 ...

  4. vue 倒计时返回首页

    1. vue页面15分钟无操作时返回首页 2. 基于vue的倒计时demo 3. 在vue2.0项目中一个简单的倒计时功能 4. vue重新发送验证码 5. 表格<td>里面文字垂直显示

  5. BFS:八数码问题

    #include <iostream> #include <cstdlib> #include <cstdio> #include <cstring> ...

  6. android edittext 获取焦点并弹出软键盘

    editText.setFocusable(true); editText.setFocusableInTouchMode(true); editText.requestFocus(); activi ...

  7. Web API: Security: Authentication and Authority

    原文地址: http://www.asp.net/web-api/overview/security/authentication-and-authorization-in-aspnet-web-ap ...

  8. window对象中的一些重要的属性和方法(笔记)

    setTimeout()方法用来实现一个函数在指定的毫秒数之后运行:setTimeout()返回一个值,这个值可以传递给clearTimeout()用于取消这个函数的执行.由于历史原因,setTime ...

  9. LintCode 58: Compare Strings

    LintCode 58: Compare Strings 题目描述 比较两个字符串A和B,确定A中是否包含B中所有的字符.字符串A和B中的字符都是大写字母. 样例 给出A = "ABCD&q ...

  10. 20155323 2016-2017-2 《Java程序设计》第7周学习总结

    20155323 2016-2017-2 <Java程序设计>第7周学习总结 使用Lambda语法来代替匿名的内部类,代码不仅简洁,而且还可读. 时间的度量:GMT.UT.TAI.UTC. ...