public class Flee {
boolean check(int[] x, int[] y, double r)
{
int n = x.length;
for(int i = 0; i < n; i++)
if(x[i]*x[i] + y[i]*y[i] <= r*r)
return true;
boolean linked[][] = new boolean[n][n];
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
if((x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]) <= 4*r*r)
linked[i][j] = true;
for(int start = 0; start < n; start++)
{
double[] maxVal = new double[n];
for(int i = 0; i < n; i++)
maxVal[i] = -1000;
maxVal[start] = 0;
for(int iteration = 1; iteration <= n; iteration ++)
{
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
if(linked[i][j])
{
double delta
= Math.
atan2(y
[j
], x
[j
]) - Math.
atan2(y
[i
], x
[i
]); delta
= delta
+ Math.
PI * 2; delta
= delta
- Math.
PI * 2; maxVal
[j
] = Math.
max(maxVal
[j
], maxVal
[i
] + delta
); }
}
if(maxVal
[start
] >= 2 * Math.
PI - 1e
-9
) return true;
}
return false;
}
public double maximalSafetyLevel(int[] x, int[] y)
{
double L = 0, R = 2000, M = 0;
for(int iteration = 1; iteration <= 100; iteration ++)
{
M = (L + R) / 2;
if(check(x, y, M))
R = M;
else
L = M;
}
return M;
}
}
cHVibGljIGNsYXNzIEZsZWUgewoKICAgIGJvb2xlYW4gY2hlY2soaW50W10geCwgaW50W10geSwgZG91YmxlIHIpCiAgICB7CiAgICAgICAgaW50IG4gPSB4Lmxlbmd0aDsKICAgICAgICBmb3IoaW50IGkgPSAwOyBpIDwgbjsgaSsrKQogICAgICAgICAgICBpZih4W2ldKnhbaV0gKyB5W2ldKnlbaV0gPD0gcipyKQogICAgICAgICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgYm9vbGVhbiBsaW5rZWRbXVtdID0gbmV3IGJvb2xlYW5bbl1bbl07CiAgICAgICAgZm9yKGludCBpID0gMDsgaSA8IG47IGkrKykKICAgICAgICAgICAgZm9yKGludCBqID0gMDsgaiA8IG47IGorKykKICAgICAgICAgICAgICAgIGlmKCh4W2ldLXhbal0pKih4W2ldLXhbal0pICsgKHlbaV0teVtqXSkqKHlbaV0teVtqXSkgPD0gNCpyKnIpCiAgICAgICAgICAgICAgICAgICAgbGlua2VkW2ldW2pdID0gdHJ1ZTsKICAgICAgICBmb3IoaW50IHN0YXJ0ID0gMDsgc3RhcnQgPCBuOyBzdGFydCsrKQogICAgICAgIHsKICAgICAgICAgICAgZG91YmxlW10gbWF4VmFsID0gbmV3IGRvdWJsZVtuXTsKICAgICAgICAgICAgZm9yKGludCBpID0gMDsgaSA8IG47IGkrKykKICAgICAgICAgICAgICAgIG1heFZhbFtpXSA9IC0xMDAwOwogICAgICAgICAgICBtYXhWYWxbc3RhcnRdID0gMDsKICAgICAgICAgICAgZm9yKGludCBpdGVyYXRpb24gPSAxOyBpdGVyYXRpb24gPD0gbjsgaXRlcmF0aW9uICsrKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBmb3IoaW50IGkgPSAwOyBpIDwgbjsgaSsrKQogICAgICAgICAgICAgICAgICAgIGZvcihpbnQgaiA9IDA7IGogPCBuOyBqKyspCiAgICAgICAgICAgICAgICAgICAgICAgIGlmKGxpbmtlZFtpXVtqXSkKICAgICAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgZG91YmxlIGRlbHRhID0gTWF0aC5hdGFuMih5W2pdLCB4W2pdKSAtIE1hdGguYXRhbjIoeVtpXSwgeFtpXSk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZihNYXRoLmFicyhkZWx0YSArIE1hdGguUEkgKiAyKSA8IE1hdGguYWJzKGRlbHRhKSkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkZWx0YSA9IGRlbHRhICsgTWF0aC5QSSAqIDI7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBlbHNlIGlmKE1hdGguYWJzKGRlbHRhIC0gTWF0aC5QSSoyKSA8IE1hdGguYWJzKGRlbHRhKSkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkZWx0YSA9IGRlbHRhIC0gTWF0aC5QSSAqIDI7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBtYXhWYWxbal0gPSBNYXRoLm1heChtYXhWYWxbal0sIG1heFZhbFtpXSArIGRlbHRhKTsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmKG1heFZhbFtzdGFydF0gPj0gMiAqIE1hdGguUEkgLSAxZS05KQogICAgICAgICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgfQogICAgICAgIHJldHVybiBmYWxzZTsKICAgIH0KCiAgICBwdWJsaWMgZG91YmxlIG1heGltYWxTYWZldHlMZXZlbChpbnRbXSB4LCBpbnRbXSB5KQogICAgewogICAgICAgIGRvdWJsZSBMID0gMCwgUiA9IDIwMDAsIE0gPSAwOwogICAgICAgIGZvcihpbnQgaXRlcmF0aW9uID0gMTsgaXRlcmF0aW9uIDw9IDEwMDsgaXRlcmF0aW9uICsrKQogICAgICAgIHsKICAgICAgICAgICAgTSA9IChMICsgUikgLyAyOwogICAgICAgICAgICBpZihjaGVjayh4LCB5LCBNKSkKICAgICAgICAgICAgICAgIFIgPSBNOwogICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICBMID0gTTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIE07CiAgICB9Cn0K