POJ 2069 模拟退火算法
Time Limit: 1000MS | Memory Limit: 65536K | |||
Total Submissions: 6422 | Accepted: 1591 | Special Judge |
Description
According to this theory, starts we are observing are not independent objects, but only small portions of larger objects called super stars. A super star is filled with invisible (or transparent) material, and only a number of points inside or on its surface shine. These points are observed as stars by us.
In order to verify this theory, Dr. Extreme wants to build motion equations of super stars and to compare the solutions of these equations with observed movements of stars. As the first step, he assumes that a super star is sphere-shaped, and has the smallest possible radius such that the sphere contains all given stars in or on it. This assumption makes it possible to estimate the volume of a super star, and thus its mass (the density of the invisible material is known).
You are asked to help Dr. Extreme by writing a program which, given the locations of a number of stars, finds the smallest sphere containing all of them in or on it. In this computation, you should ignore the sizes of stars. In other words, a star should be regarded as a point. You may assume the universe is a Euclidean space.
Input
n
x1 y1 z1
x2 y2 z2
. . .
xn yn zn
The first line of a data set contains an integer n, which is the number of points. It satisfies the condition 4 <= n <= 30.
The location of n points are given by three-dimensional orthogonal coordinates: (xi, yi, zi) (i = 1, ..., n). Three coordinates of a point appear in a line, separated by a space character. Each value is given by a decimal fraction, and is between 0.0 and 100.0 (both ends inclusive). Points are at least 0.01 distant from each other.
The end of the input is indicated by a line containing a zero.
Output
Sample Input
4
10.00000 10.00000 10.00000
20.00000 10.00000 10.00000
20.00000 20.00000 10.00000
10.00000 20.00000 10.00000
4
10.00000 10.00000 10.00000
10.00000 50.00000 50.00000
50.00000 10.00000 50.00000
50.00000 50.00000 10.00000
0
Sample Output
7.07107
34.64102
这道题和POJ2420相比有一些不同的地方
这道题采取直接在图中随机取一个点搜索会很难控制精度,通过看其他巨佬的做法才发现从(0,0,0)这个点搜索,遍历比较得到各个点与当前所在点距离最远的那个点,
然后缩短这个点与当前点的的距离来同时控制方向和精度才是这道题最简单的做法
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define it iterator
#define ll long long
#define eb emplace_back
#define lowbit(x) x & -x
#define all(x) x.begin(),x.end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define per(x,a,b) for(int x = a; x <= b; x++)
#define rep(x,a,b) for(int x = a; x >= b; x--)
#define IO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0) const int birth = ;
const int mo = ;
const int maxn = 1e5 + ;
const int mod = 1e9 + ;
const int INF = 0x3fffffff;
const double eps = 1e-; //******************THE PROGRAM BEGINING******************
struct node
{
double x, y, z;
}p[]; double dis(node a, node b)
{
return sqrt(pow(a.x - b.x, ) + pow(a.y - b.y, ) + pow(a.z - b.z, ));
} double solve(int n)
{
double ans,cmp;
double T = 100.0;
double delat = 0.98;
node now;
now.x = now.y = now.z = 0.0;
int pos = ;
while (T > eps)
{
pos = ;
ans = dis(now, p[pos]);
per(i, , n - )
{
cmp = dis(now, p[i]);
if (cmp > ans)
{
pos = i;
ans = cmp;
}
}
now.x += (p[pos].x - now.x) / ans * T;
now.y += (p[pos].y - now.y) / ans * T;
now.z += (p[pos].z - now.z) / ans * T;
T *= delat;
}
return ans;
} int main()
{
int n;
while (scanf("%d",&n) && n)
{
per(i, , n - )
scanf("%lf %lf %lf", &p[i].x, &p[i].y, &p[i].z); printf("%.5lf\n",solve(n));
}
return ;
}
POJ 2069 模拟退火算法的更多相关文章
- POJ 2069 Super Star(计算几何の最小球包含+模拟退火)
Description During a voyage of the starship Hakodate-maru (see Problem 1406), researchers found stra ...
- 初探 模拟退火算法 POJ2420 HDU1109
模拟退火算法来源于固体退火原理,更多的化学物理公式等等这里不再废话,我们直接这么来看 模拟退火算法简而言之就是一种暴力搜索算法,用来在一定概率下查找全局最优解 找的过程和固体退火原理有所联系,一般来讲 ...
- POJ 1379 模拟退火
模拟退火算法,很久之前就写过一篇文章了.双倍经验题(POJ 2420) 题意: 在一个矩形区域内,求一个点的距离到所有点的距离最短的那个,最大. 这个题意,很像二分定义,但是毫无思路,也不能暴力枚举, ...
- 模拟退火算法-[HDU1109]
模拟退火算法的原理模拟退火算法来源于固体退火原理,将固体加温至充分高,再让其徐徐冷却,加温时,固体内部粒子随温升变为无序状,内能增大,而徐徐冷却时粒子渐趋有序,在每个温度都达到平衡态,最后在常温时达到 ...
- 【高级算法】模拟退火算法解决3SAT问题(C++实现)
转载请注明出处:http://blog.csdn.net/zhoubin1992/article/details/46453761 ---------------------------------- ...
- 模拟退火算法(SA)求解TSP 问题(C语言实现)
这篇文章是之前写的智能算法(遗传算法(GA).粒子群算法(PSO))的补充.其实代码我老早之前就写完了,今天恰好重新翻到了,就拿出来给大家分享一下,也当是回顾与总结了. 首先介绍一下模拟退火算法(SA ...
- 原创:工作指派问题解决方案---模拟退火算法C实现
本文忽略了对于模拟退火的算法的理论讲解,读者可参考相关的博文或者其他相关资料,本文着重于算法的实现: /************************************************ ...
- BZOJ 3680: 吊打XXX【模拟退火算法裸题学习,爬山算法学习】
3680: 吊打XXX Time Limit: 10 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 3192 Solved: 1198[Sub ...
- OI骗分神器——模拟退火算法
前言&&为什么要学模拟退火 最近一下子学了一大堆省选算法,所以搞一个愉快一点的东西来让娱乐一下 其实是为了骗到更多的分,然后证明自己的RP. 说实话模拟退火是一个集物理与IT多方面知识 ...
随机推荐
- jsp中常用的标签
jsp本质上就是一个servlet,只是tomcat会将其翻译成servlet,servlet本质上是一个类,那么jsp也是一个类.jsp中各种标签都会被tomcat翻译成各种基本的java代码 如果 ...
- 基于分布式思想下的RPC解决方案--笔记
分布式: RPC可以提高系统稳定性,比如说,我们的订单服务程序更新出BUG,导致内存溢出,是这台服务器宕机了,但是它只会影响的整个系统的订单业务部分,对于用户注册登录等业务没有影响,同样对于系统的日志 ...
- 【转】字符串匹配的KMP算法:移动位数 = 已匹配 - 部分匹配值(共有长度)
计算机的基本任务之一. 举例来说,有一个字符串"BBC ABCDAB ABCDABCDABDE",我想知道,里面是否包含另一个字符串"ABCDABD"? 许多算 ...
- VMTurbo:应对散乱虚拟机的强劲工具
随着服务器虚拟化技术越来越成熟,虚拟机散乱(VM sprawl)和主机资源管理成为了虚拟化数据中心的管理员眼里的两大问题.面对这种情形,一种可行的解决办法就是使用一款名为VMTurbo(vmturbo ...
- static 与 extern 关键字描述说明
使用static 定义的变量和函数只能用于本模块即为本文件 使用extern 定义的变量和函数可以用于其他模块的引用
- 6-Collision-hdu5114(小球碰撞)
Collision Time Limit: 15000/15000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others)Tot ...
- Golang之字符串操作(反转中英文字符串)
//字符串反转package main import "fmt" func reverse(str string) string { var result string strLe ...
- VS2010+SVN
小乌龟版本用1.6,用1.8时老报错SVN是2.06, SVN Server是2.1.9
- Activity ViewPager Fragment框架的生命周期
1.Fragment的生命周期函数 onAttach.onCreate.onCreateView.onViewCreated.onActivityCreated.onStart.onResume.on ...
- Linq编译带来的诡异错误
今天遇到一个很诡异的问题,初步猜测是Linq编译以及编译器自动优化带来的原因,对IL不是很熟悉,所以懒得去追了. 贴个代码出来,希望能抛砖引玉,得到正解. 注意到我用原始的foreach语句代替了li ...