题目链接:Super Star
这个我真不会,只能给出代码了。
//就是下面的我看不懂了,不清楚为什么要这样做,有看懂请留言告知
p.x+=(pot[id].x-p.x)/r_maxn*t;
p.y+=(pot[id].y-p.y)/r_maxn*t;
p.z+=(pot[id].z-p.z)/r_maxn*t;
代码:
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
#define inf 0x3f3f3f3f
const int maxn=50;
struct node
{
double x,y,z;
} pot[maxn];
double count(node a,node 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));
}
void reduce(node &p,double &r,double t,int n)
{
double r_maxn=-inf;//距离
int id=0;//最远点
for(int i=0;i<n;i++)//查找与当前球点最远的点,和距离
{
double len=count(pot[i],p);
if(len>r_maxn)
{
r_maxn=len;
id=i;
}
}
r=min(r_maxn,r);//更新半径
//就是下面的我看不懂了,不清楚为什么要这样做,有看懂请留言告知
p.x+=(pot[id].x-p.x)/r_maxn*t;
p.y+=(pot[id].y-p.y)/r_maxn*t;
p.z+=(pot[id].z-p.z)/r_maxn*t;
return ;
}
double solve(int n)
{
double base=0.98;//相当于温度下降的速率吧
double t=100;//初始温度
double ans=1e-8;//最终的温度
double r=inf;//记录最终答案
node p=pot[0];//随便取一个点
while(t>ans)
{
reduce(p,r,t,n);//查找最短的半径,向球心靠近
t*=base;
}
return r;
}
int main()
{
int n;
while(~scanf("%d",&n)&&n)
{
for(int i=0; i<n; i++)
scanf("%lf%lf%lf",&pot[i].x,&pot[i].y,&pot[i].z);
double kp=solve(n);
printf("%.5lf\n",kp);
}
return 0;
}