During SRM 621 I solved only 250 problem, but after the contest I figured out the solution to 500 which I'm going to write about in the next post. Now let's focus on 250 problem.

## 250 Problem

You're given a circles on the plane and the integer . The -th circle has a center in and a radius , where and . A special circle has to be placed with a center in and a radius chosen uniformly at random from an interval . We say that the special circle is **good** when there is no other circle which intersects with the special circle, in other words all points lying within any regular circle has to be either inside or outside the special circle. Your task is to compute the probability that the special circle is good. Let's consider an example input:

A very basic but a crucial observation is that for any regular circle it doesn't matter what's the relative position of that circle. Only the radius and the distance from it's center to matter. So we can transform the problem from 3D to 2D which is always good.

Let be the distance from the center of the -th circle to . Then the -th circle corresponds to a segment and choosing corresponds to choosing a point from . The above example corresponds to the following picture:

For a given , we're interested in segments in which lies in any where and doesn't intersect with any regular circle. For our example, the good segments are marked green in the following picture:

Now, it's easy to see that the probability we're looking for equals , where is the length of a sum of segments corresponding to the regular circles limited to . We can compute easily by sorting the segments and then process these segments one by one and count the amount of space where at least one segment is open. If you're interested, I'm putting my code below:

```
double dist(int x, int y)
{
return sqrt(pow(x, 2) + pow(y, 2));
}
class RadioRange {
public:
double RadiusProbability(vector
``` X, vector Y, vector R, int Z) {
vector > v;
FOR(i, X.size())
{
double d = dist(X[i], Y[i]);
v.pb(mp(max(d - R[i], 0.0), 0));
v.pb(mp(d + R[i], 1));
}
sort(ALL(v));
int open = 0;
double checkpoint = 0.0;
double res = 0.0;
FOR(i, v.size())
{
double d = v[i].fi;
if(d > Z) break;
if(v[i].se == 0)
{
if(open == 0)
{
checkpoint = d;
}
open++;
}
else
{
open--;
if(open == 0)
{
res += d - checkpoint;
}
}
}
if(open > 0)
{
res += Z - checkpoint;
}
return 1 - res / Z;
}
};