欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 美景 > 三维最小球覆盖(模拟退火)

三维最小球覆盖(模拟退火)

2025/11/6 21:14:17 来源:https://blog.csdn.net/yusen_123/article/details/142007053  浏览:    关键词:三维最小球覆盖(模拟退火)

地址:https://codeforces.com/gym/101981/attachments

代码:

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <math.h>
#include <map>
#include <sstream>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <array>
#include <climits>
using namespace std;
#define   LL long long
#define ull unsigned long long 
#define LD long double 
const LL MAX = (LL)1e18;
const int  N = 1e3 + 10;
const double eps = 1e-3;
const double PI = acos(-1);
typedef struct Point 
{
    double x, y, z;
    Point operator -(const Point  &u)const 
    {
       return  {x - u.x, y - u.y, z - u.z};
    }

};
int n;
Point p[N];
double getlen(Point a, Point b) 
{
    Point d=a-b;
    return sqrt(d.x * d.x + d.y * d.y + d.z * d.z);
}
double solve() 
{
    double st = 1000, rate = 0.99999;
    Point now = p[1];
    double ans = MAX;
    while (st > eps) 
    {
        int cur = 0;
        double maxx =0;
        for (int i = 1; i <= n; i++)
            if (getlen(now, p[i]) > maxx) cur = i, maxx = getlen(now, p[i]);
        ans = min(ans, getlen(now, p[cur]));
        now.x += (p[cur].x - now.x) * (st / 1000);
        now.y += (p[cur].y - now.y) * (st / 1000);
        now.z+= (p[cur].z - now.z) * (st / 1000);
        st *= rate;
    }
    //cout << now.x << " " << now.y << " " << now.z << endl;
    return ans;

}
int  main()
{
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> p[i].x >> p[i].y >> p[i].z;
    printf("%.10lf\n", solve());
    return 0;
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词