CF 106E(Space Rescuers-费马点+模拟退火)

本文介绍了一种使用费马点和模拟退火方法来确定银河系中最佳救援站位置的技术。该方法通过不断调整候选位置使其远离最远行星的距离最小化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

E. Space Rescuers
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

The Galaxy contains n planets, there are many different living creatures inhabiting each planet. And each creature can get into troubles! Space rescuers know it perfectly well and they are always ready to help anyone who really needs help. All you need to do is call for them.

Now the space rescuers plan to build the largest in the history of the Galaxy rescue station; however, the rescue station's location is yet to be determined. As some cases are real emergencies, the rescuers want to find such a point in the Galaxy from which it would be possible to get to the remotest planet in the minimum possible time. In other words, the rescuers need such point in the space that the distance between it and the planet remotest from it was minimal (if we compare this point with all other possible points in the space). Unfortunately, the rescuers can't sole this problem.

As the planets are quite remote from each other, they can be considered as points in Euclidean three-dimensional space. The distance between points (xi, yi, zi) and (xj, yj, zj) can be calculated by the formula . The rescue station can be positioned in any point in the space. It can also coincide with some planet.

Galaxy is in danger! Save the space rescuers and find the required point for them.

Input

The first line of the input file contains integer n — the number of planets (1 ≤ N ≤ 100). Each of the following n lines contains information about the planets. The i-th line contains three integers xi, yi, zi — the coordinates of the i-th planet ( - 104 ≤ xi, yi, zi ≤ 1041 ≤ i ≤ n). No two planets coincide.

Output

Print on the first line of the output file three space-separated real numbers x0, y0, z0 — the coordinates for the future base. If there are several solutions, you are allowed to print any of them. The answer will be accepted if the distance from this point to the remotest planet will differ from the juries' variant in no more than 10 - 6 in absolute or relative value.

Sample test(s)
input
5
5 0 0
-5 0 0
0 3 4
4 -3 0
2 2 -2
output
0.000 0.000 0.000


费马点+模拟退火。。。今天yzc无聊说的。。。

每次向最远点反向挪。。长度退火。。。

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define MAXN (100+10)
#define eps 1e-10
long long mul(long long a,long long b){return (a*b)%F;}
long long add(long long a,long long b){return (a+b)%F;}
long long sub(long long a,long long b){return (a-b+(a-b)/F*F+F)%F;}
typedef long long ll;
long double sqr(long double x){return x*x;}
struct P
{
	long double x,y,z;
	P(){x=y=z=0;}
	P(long double _x,long double _y,long double _z):x(_x),y(_y),z(_z){}
	friend long double dis(P a,P b){return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y)+sqr(a.z-b.z));}
	friend P operator+(P a,P b){return P(a.x+b.x,a.y+b.y,a.z+b.z);}
}a[MAXN],st;
struct V
{
	long double x,y,z;
	V(){x=y=z=0;}
	V(long double _x,long double _y,long double _z):x(_x),y(_y),z(_z){}
	V(P a,P b):x(b.x-a.x),y(b.y-a.y),z(b.z-a.z){}
	friend V operator+(V a,V b){return V(a.x+b.x,a.y+b.y,a.z+b.z);}
	friend V operator*(V a,long double b){return V(a.x*b,a.y*b,a.z*b);	}
};
P operator+(P a,V b){return P(a.x+b.x,a.y+b.y,a.z+b.z);}
int n;
int main()
{
	//freopen("CF106E.in","r",stdin);
	cin>>n;
	For(i,n) cin>>a[i].x>>a[i].y>>a[i].z,st=st+a[i];
	st.x/=n,st.y/=n,st.z/=n;
	long double step=1;
	while (step>eps)
	{
		int p=1;
		Fork(i,2,n) 
			if (dis(st,a[i])>dis(st,a[p])) p=i;
		st=st+V(st,a[p])*step;		
		step*=0.999;
	}
	//cout.setf(ios::fixed);
	//cout.precision(2);
	cout<<st.x<<' '<<st.y<<' '<<st.z<<endl;
	
	return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值