POJ 2069 Super Star 爬山

题目大意

空间最小球覆盖

思路

临滚粗前做点水题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;
}
时间: 2024-11-10 03:56:59

POJ 2069 Super Star 爬山的相关文章

POJ 2069 Super Star

模拟退火. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #define maxn 30 #define eps 1e-7 using namespace std; struct point { double x,y,z; }p[maxn],s; int n; double delta=0.98; double d

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

解题思路: 给出空间内的n个点,找出覆盖这n个点的最小球的半径.用模拟退火来做. #include <iostream> #include <cstring> #include <cstdlib> #include <cstdio> #include <vector> #include <queue> #include <stack> #include <map> #include <cmath>

模拟退火 (poj 2420, poj 2069)

模拟退火基本知识 其伪代码例如以下: Let s = s0 For k = 0 through k_max (exclusive): T := temperature(k / k_max) Pick a random neighbour, s_new := neighbour(s) If P(E(s), E(s_new), T) > random(0, 1), move to the new state: s := s_new Output: the final state s 样例: poj

三分 POJ 2420 A Star not a Tree?

题目传送门 1 /* 2 题意:求费马点 3 三分:对x轴和y轴求极值,使到每个点的距离和最小 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <cstring> 8 #include <cmath> 9 10 const int MAXN = 1e2 + 10; 11 const int INF = 0x3f3f3f3f; 12 double x[MAXN], y[MAXN]; 13 i

POJ 2069

模拟退火算法.暂时不是很理解,待我理解了再写一个总结. 求的是球的最小包含 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; const int MAXN=35; const double inf=1e10; const double eps=1e-8; struct

POJ 2420 A Star not a Tree? 爬山算法

B - A Star not a Tree? Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88808#problem/B Description Luke wants to upgrade his home computer network from 10mbs to 100mbs. His existing network uses 10ba

[POJ2069]Super Star(模拟退火)

题目链接:http://poj.org/problem?id=2069 题意:求一个半径最小的球,使得它可以包围住所有点. 模拟退火,圆心每次都去找最远那个点,这样两点之间的距离就是半径,那么接下来移动的方向肯定就是朝着这个最远点移动,保证比例相同且在球内的情况下移动. 不看题解想不到,这个东西有点难啊... 1 #include <algorithm> 2 #include <iostream> 3 #include <iomanip> 4 #include <

[POJ 2420] A Star not a Tree?

A Star not a Tree? Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4058   Accepted: 2005 Description Luke wants to upgrade his home computer network from 10mbs to 100mbs. His existing network uses 10base2 (coaxial) cables that allow you

POJ 2420 A Star not a Tree? (计算几何-费马点)

A Star not a Tree? Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3435   Accepted: 1724 Description Luke wants to upgrade his home computer network from 10mbs to 100mbs. His existing network uses 10base2 (coaxial) cables that allow you