Time Limit: 1000MS | Memory Limit: 65536K | |||
Total Submissions: 3198 | Accepted: 853 | Special Judge |
Description
as a description of actors or singers. It is a revolutionary theory in astronomy.
According to this theory, starts we are observing are not independent objects, but only small portions of larger objects called super stars. A super star is filled with invisible (or transparent) material, and only a number of points inside or on its surface
shine. These points are observed as stars by us.
In order to verify this theory, Dr. Extreme wants to build motion equations of super stars and to compare the solutions of these equations with observed movements of stars. As the first step, he assumes that a super star is sphere-shaped, and has the smallest
possible radius such that the sphere contains all given stars in or on it. This assumption makes it possible to estimate the volume of a super star, and thus its mass (the density of the invisible material is known).
You are asked to help Dr. Extreme by writing a program which, given the locations of a number of stars, finds the smallest sphere containing all of them in or on it. In this computation, you should ignore the sizes of stars. In other words, a star should be
regarded as a point. You may assume the universe is a Euclidean space.
Input
n
x1 y1 z1
x2 y2 z2
. . .
xn yn zn
The first line of a data set contains an integer n, which is the number of points. It satisfies the condition 4 <= n <= 30.
The location of n points are given by three-dimensional orthogonal coordinates: (xi, yi, zi) (i = 1, ..., n). Three coordinates of a point appear in a line, separated by a space character. Each value is given by a decimal fraction, and is between 0.0 and 100.0
(both ends inclusive). Points are at least 0.01 distant from each other.
The end of the input is indicated by a line containing a zero.
Output
0.00001.
Sample Input
4 10.00000 10.00000 10.00000 20.00000 10.00000 10.00000 20.00000 20.00000 10.00000 10.00000 20.00000 10.00000 4 10.00000 10.00000 10.00000 10.00000 50.00000 50.00000 50.00000 10.00000 50.00000 50.00000 50.00000 10.00000 0
Sample Output
7.07107 34.64102
#include<iostream> #include<cmath> #include<ctime> #include<cstdio> using namespace std; const int MAXN=50; const double eps=1e-8; int n; struct Point { double x,y,z; }myPoint[MAXN],op; double GetDis(const Point &a,const 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() { double ret,delta=100.0; double maxDis,tempDis; int i,id; while(delta>eps) { id=0; maxDis=GetDis(op,myPoint[id]); for(i=1;i<n;i++) { tempDis=GetDis(op,myPoint[i]); if(tempDis>maxDis) { maxDis=tempDis; id=i; } } ret=maxDis; op.x+=(myPoint[id].x-op.x)/maxDis*delta; op.y+=(myPoint[id].y-op.y)/maxDis*delta; op.z+=(myPoint[id].z-op.z)/maxDis*delta; delta*=0.98; } return ret; } int main() { int i; while(scanf("%d",&n)!=EOF) { if(0==n)break; for(i=0;i<n;i++) scanf("%lf%lf%lf",&myPoint[i].x,&myPoint[i].y,&myPoint[i].z); op.x=op.y=op.z=0.0; printf("%.5lf\n",Solve()); } return 0; }
Buried memory
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2213 Accepted Submission(s): 1212
The world king Sconbin is not the exception.One day,Sconbin was sleeping,then swakened by one nightmare.It turned out that his love letters to Dufein were made public in his dream.These foolish letters might ruin his throne.Sconbin decided to destroy the letters
by the military exercises's opportunity.The missile is the best weapon.Considered the execution of the missile,Sconbin chose to use one missile with the minimum destruction.
Sconbin had writen N letters to Dufein, she buried these letters on different places.Sconbin got the places by difficult,he wants to know where is the best place launch the missile,and the smallest radius of the burst area. Let's help Sconbin to get the award.
and y coordinate.N=0 is the end of the input file.
output numbers are rounded to the second digit after the decimal point.
3 1.00 1.00 2.00 2.00 3.00 3.00 0
2.00 2.00 1.41
#include<iostream> #include<cmath> #include<ctime> #include<cstdio> using namespace std; const int MAXN=500+10; const double eps=1e-8; int n; struct Point { double x,y; }myPoint[MAXN],op; double GetDis(const Point &a,const Point &b) { return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); } void Solve() { double ret,delta=100.0; double maxDis,tempDis; int i,id; while(delta>eps) { id=0; maxDis=GetDis(op,myPoint[id]); for(i=1;i<n;i++) { tempDis=GetDis(op,myPoint[i]); if(tempDis>maxDis) { maxDis=tempDis; id=i; } } ret=maxDis; op.x+=(myPoint[id].x-op.x)/maxDis*delta; op.y+=(myPoint[id].y-op.y)/maxDis*delta; delta*=0.98; } printf("%.2lf %.2lf %.2lf\n",op.x,op.y,ret); } int main() { int i; while(scanf("%d",&n)!=EOF) { if(0==n)break; op.x=op.y=0; for(i=0;i<n;i++) { scanf("%lf%lf",&myPoint[i].x,&myPoint[i].y); op.x+=myPoint[i].x; op.y+=myPoint[i].y; } op.x/=n; op.x/=n; Solve(); } return 0; }