POJ 2069 Super Star(模拟退火,最小球覆盖)

解题思路:

给出空间内的n个点,找出覆盖这n个点的最小球的半径。用模拟退火来做。

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <cmath>
#include <set>
#define LL long long
using namespace std;
const int MAXN = 50;
const double eps = 1e-6;
struct Point
{
    double x, y, z;
    Point(double x = 0, double y = 0, double z = 0) : x(x), y(y), z(z) { }
};
Point operator - (Point A, Point B)
{
    return Point(A.x - B.x, A.y - B.y, A.z - B.z);
}
double dis(Point A, Point B)
{
    double x = A.x - B.x;
    double y = A.y - B.y;
    double z = A.z - B.z;
    return sqrt(x * x + y * y + z * z);
}
int n;
Point p[MAXN];
double SA(Point start)
{
    double delta = 100.0;
    double ans = 1e20;
    while(delta > eps)
    {
        int d = 0;
        for(int i=0;i<n;i++)
        {
            if(dis(p[i], start) > dis(p[d], start))
                d = i;
        }
        double r = dis(start, p[d]);
        ans = min(ans, r);
        start.x += (p[d].x - start.x) / r * delta;
        start.y += (p[d].y - start.y) / r * delta;
        start.z += (p[d].z - start.z) / r * delta;
        delta *= 0.98;
    }
    return ans;
}
int main()
{
    int T, kcase = 1;
    //scanf("%d", &T);
    while(scanf("%d", &n) && n)
    {
        //scanf("%d", &n);
        for(int i=0;i<n;i++)
            scanf("%lf%lf%lf", &p[i].x, &p[i].y, &p[i].z);
        printf("%.5lf\n", SA(Point(0,0,0)));
    }
    return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值