POJ2069 最小球体覆盖, 模拟退火
2014-08-27 13:06
204 查看
只是套了个模板,模拟退火具体的过程真心不懂阿
//#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #include <stdio.h> #include <iostream> #include <cstring> #include <cmath> #include <stack> #include <queue> #include <vector> #include <algorithm> #define ll long long #define Max(a,b) (((a) > (b)) ? (a) : (b)) #define Min(a,b) (((a) < (b)) ? (a) : (b)) #define Abs(x) (((x) > 0) ? (x) : (-(x))) using namespace std; const int INF = 0x3f3f3f3f; const int MAXN = 220; const double eps = 1e-8; int n; struct POINT{ double x,y,z; }ps[35],q; double dist(POINT a,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 maxD(POINT p){ double res = 0; int i, k = 0; for(i = 0; i < n ; ++i){ double tmp = dist(p,ps[i]); if(tmp > res){ k = i; res = dist(p,ps[i]); } } return k; } double BallCover(){ double step = 100, ans = INF; q.x = q.y = q.z = 0.0; while(step > eps){ int d = maxD(q); double tmp = dist(ps[d],q); if(tmp < ans) ans=tmp; double dx = ps[d].x - q.x; double dy = ps[d].y - q.y; double dz = ps[d].z - q.z; dx /= tmp; dy /= tmp; dz /= tmp; q.x += (dx*step); q.y += (dy*step); q.z += (dz*step); step *= 0.98; } return ans; } int main(){ int i; while(EOF != scanf("%d",&n)){ if(0 == n) break; for(i = 0; i < n ; ++i) scanf("%lf%lf%lf",&ps[i].x,&ps[i].y,&ps[i].z); printf("%.5f\n",BallCover()); } return 0; }
相关文章推荐
- HDU 3007 Buried memory(点集最小圆覆盖 模拟退火解法)
- HDU 4766 模拟退火(最小圆覆盖) + 二分
- hdu3932 最小圆覆盖-模拟退火实现-3+
- POJ 2069 Super Star(模拟退火,最小球覆盖)
- poj2069Super Star【空间最小球覆盖模拟退火】
- 智能算法---模拟退火搜索函数最小值
- 【模拟退火】poj2069 Super Star
- poj-1548-Robots- 贪心+模拟 / 最小路径覆盖
- POJ 最小球覆盖 模拟退火
- [网络流24题] No3_最小路径覆盖问题
- poj_1422_最小路径覆盖
- 网络流24题之四 魔术球问题 最小路径覆盖
- 二分图----最大匹配,最小点覆盖,最大点独立集
- HDU 3335 Divisibility(Dilworth定理+最小路径覆盖)
- 最小路径覆盖_zoj1525_最小路径覆盖+水
- POJ 1463 浅谈简单树形动态规划及树上最小点覆盖
- 贪心法求树的最小支配集,最小点覆盖,最大独立集
- 行列的二分图模型 最小点覆盖——pku3041
- hdu 1528+hdu 1962(最小覆盖)
- 最小路径覆盖