Can you explain it to me on example1. Given two points the unique minimal radius circle intersecting these is the circle with center in the middle and half the distance as radius.

Moderator: Board moderators
Do you think the above algorithm is correct. Have anyone using that algorithm got ACCEPTED SUBMITION ?.arnsfelt wrote:
- 1. Given two points the unique minimal radius circle intersecting these is the circle with center in the middle and half the distance as radius.
2. Given three points that are not colinear there is a unique circle that intersect these.
3. Given n>1 points it it possible to choose two or three points such that the minimal circle including all the points is as descriped above.
Code: Select all
EPS ==> 1e-9
N - number of points in polygon
R *= 2.0; /* diameter of circle */
max = 0.0;
for(i=0;i<N;i++)
for(j=i+1;j<N;j++)
{
x = points[i][0] - points[j][0];
y = points[i][1] - points[j][1];
tmp = x*x + y*y;
if(tmp > max) max = tmp;
}
max = sqrt(max) + EPS;
if(max <= R)
printf("The polygon can be packed in the circle.\n");
else
printf("There is no way of packing that polygon.\n");
My solution is O(N^3) too, and runs on 0.004 seconds.alex[LSD] wrote:The thing is - My solution is N^3. I am #326 of 331 in the promlems list with 1.68s.
So please, enlighten my butt, tell me about how to solve it fast.
P.S. I d really appreciate that.
Hmmm, for each pair of points I get the center of the circle of radius R that has them on the perimeter. Simple geometry:alex[LSD] wrote:Horape I dont get what do you mean by "test".
I also went through all the pairs, and for each pair I found the MINIMUM ANGLE from a 3rd point to the line segment. I needed minimum angles for two cases separately : for "above" the line segment and for "below". Did you do smth like this? I guess my GetAngle() was too time-consuming...
Code: Select all
ab = b-a; // vector
abp = perp(ab); // perp (x,y) = (y,-x)
d = dist(a,b)
if (d>2*R)
there is no way for a circle of radius R to include both points.
// dp
It isn't binary search, nor something like that, as far as i understand. I test each pair of vertices, and then test it again every vertex.alex[LSD] wrote:Sounds like binary search.
So where do you get the R value? And why dont you go both directions from middle of AB?
And I do AB and BA, that's why I just choose one of the points and not both.The last line of the input case will be a real number indicating the radius R of the circle.