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

来源:互联网 发布:卖域名 赚钱么 编辑:程序博客网 时间:2024/06/05 08:31
 

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

分类: 模拟退火 费马点 127人阅读 评论(0) 收藏 举报

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
55 0 0-5 0 00 3 44 -3 02 2 -2
output
0.000 0.000 0.000


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

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

[cpp] view plaincopy
  1. #include<cstdio>  
  2. #include<cstring>  
  3. #include<cstdlib>  
  4. #include<algorithm>  
  5. #include<functional>  
  6. #include<iostream>  
  7. #include<cmath>  
  8. #include<cctype>  
  9. #include<ctime>  
  10. using namespace std;  
  11. #define For(i,n) for(int i=1;i<=n;i++)  
  12. #define Fork(i,k,n) for(int i=k;i<=n;i++)  
  13. #define Rep(i,n) for(int i=0;i<n;i++)  
  14. #define ForD(i,n) for(int i=n;i;i--)  
  15. #define RepD(i,n) for(int i=n;i>=0;i--)  
  16. #define Forp(x) for(int p=pre[x];p;p=next[p])  
  17. #define Lson (x<<1)  
  18. #define Rson ((x<<1)+1)  
  19. #define MEM(a) memset(a,0,sizeof(a));  
  20. #define MEMI(a) memset(a,127,sizeof(a));  
  21. #define MEMi(a) memset(a,128,sizeof(a));  
  22. #define INF (2139062143)  
  23. #define F (100000007)  
  24. #define MAXN (100+10)  
  25. #define eps 1e-10  
  26. long long mul(long long a,long long b){return (a*b)%F;}  
  27. long long add(long long a,long long b){return (a+b)%F;}  
  28. long long sub(long long a,long long b){return (a-b+(a-b)/F*F+F)%F;}  
  29. typedef long long ll;  
  30. long double sqr(long double x){return x*x;}  
  31. struct P  
  32. {  
  33.     long double x,y,z;  
  34.     P(){x=y=z=0;}  
  35.     P(long double _x,long double _y,long double _z):x(_x),y(_y),z(_z){}  
  36.     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));}  
  37.     friend P operator+(P a,P b){return P(a.x+b.x,a.y+b.y,a.z+b.z);}  
  38. }a[MAXN],st;  
  39. struct V  
  40. {  
  41.     long double x,y,z;  
  42.     V(){x=y=z=0;}  
  43.     V(long double _x,long double _y,long double _z):x(_x),y(_y),z(_z){}  
  44.     V(P a,P b):x(b.x-a.x),y(b.y-a.y),z(b.z-a.z){}  
  45.     friend V operator+(V a,V b){return V(a.x+b.x,a.y+b.y,a.z+b.z);}  
  46.     friend V operator*(V a,long double b){return V(a.x*b,a.y*b,a.z*b);  }  
  47. };  
  48. P operator+(P a,V b){return P(a.x+b.x,a.y+b.y,a.z+b.z);}  
  49. int n;  
  50. int main()  
  51. {  
  52.     //freopen("CF106E.in","r",stdin);  
  53.     cin>>n;  
  54.     For(i,n) cin>>a[i].x>>a[i].y>>a[i].z,st=st+a[i];  
  55.     st.x/=n,st.y/=n,st.z/=n;  
  56.     long double step=1;  
  57.     while (step>eps)  
  58.     {  
  59.         int p=1;  
  60.         Fork(i,2,n)   
  61.             if (dis(st,a[i])>dis(st,a[p])) p=i;  
  62.         st=st+V(st,a[p])*step;        
  63.         step*=0.999;  
  64.     }  
  65.     //cout.setf(ios::fixed);  
  66.     //cout.precision(2);  
  67.     cout<<st.x<<' '<<st.y<<' '<<st.z<<endl;  
  68.       
  69.     return 0;  
  70. }  
原创粉丝点击