POJ 2069 Super Star 爬山

16 篇文章 0 订阅
1 篇文章 0 订阅

题目大意

空间最小球覆盖

思路

临滚粗前做点水题qwq

CODE

#define _CRT_SECURE_NO_WARNINGS

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define INF 1e15
#define EPS 1e-7
#define MAX 100
using namespace std;

struct PointIII{
    double x, y, z;

    PointIII(const double &_, const double &__, const double &___):x(_), y(__), z(___) {}
    PointIII() {}
    PointIII operator +(const PointIII &a)const {
        return PointIII(x + a.x, y + a.y, z + a.z);
    }
    PointIII operator *(const double &a)const {
        return PointIII(x * a, y * a, z * a);
    }
    void Read() {
        scanf("%lf%lf%lf", &x, &y, &z);
    }
}point[MAX];

int points;
double ans, fin;

inline unsigned int Rand()
{
    return rand() * rand();
}

inline double Calc(const PointIII &p1, const PointIII &p2)
{
    return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y) + (p1.z - p2.z) * (p1.z - p2.z));
}

void SA()
{
    double T = 100.0;
    double x = 0, y = 0, z = 0;
    for(int i = 1; i <= points; ++i)
        x += point[i].x, y += point[i].y, z += point[i].z;
    PointIII now(x / points, y / points, z / points);
    ans =INF;
    while(T > EPS) {
        int p = 1;
        for(int i = 2; i <= points; ++i)
            if(Calc(now, point[i]) > Calc(now, point[p]))
                p = i;
        double r = Calc(now, point[p]);
        ans = min(ans, r);
        now.x += (point[p].x - now.x) / r * T;
        now.y += (point[p].y - now.y) / r * T;
        now.z += (point[p].z - now.z) / r * T;
        T *= .98;
    }
}

int main()
{
    while(scanf("%d", &points), points) {
        for(int i = 1; i <= points; ++i)
            point[i].Read();
        SA();
        printf("%.5f\n", ans);
    }
    return 0;
}
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值