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 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));
}
double solve()
{
    s.x=s.y=s.z=0;
    int regis=1;
    double ans=1e30,t=100;
    while (t>eps)
    {
        for (int i=1;i<=n;i++)
            if (dist(s,p[i])>dist(s,p[regis]))
                regis=i;
        double mt=dist(s,p[regis]);
        ans=min(ans,mt);
        s.x+=(p[regis].x-s.x)/mt*t;
        s.y+=(p[regis].y-s.y)/mt*t;
        s.z+=(p[regis].z-s.z)/mt*t;
        t*=delta;
    }
    return ans;
}
int main()
{
    for (;;)
    {
        scanf("%d",&n);
        if (n==0) break;
        for (int i=1;i<=n;i++)
            scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].z);
        printf("%.5lf\n",solve());
    }
    return 0;
}
时间: 2024-10-10 18:14:38

POJ 2069 Super Star的相关文章

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

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

[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

POJ 2420 A Star not a Tree? (模拟退火)

题目地址:POJ 2420 今天在比赛遇到了这题..于是现场学了一下模拟退火.... 这题是先初始化为一个点,然后不断趋近距离和最短的点.还是挺简单的.. 代码如下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #include <ctype.h&g