import java.io.*;
import java.util.*;
class main {
static int N;
static int L;
static ArrayList<Coordinate> coordinates;
public static void main(String[] args) throws IOException {
BufferedReader br;
PrintWriter out;
StringTokenizer st;
try {
br = new BufferedReader(new FileReader("highcard.in"));
out = new PrintWriter(new BufferedWriter(new FileWriter("highcard.out")));
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
st = new StringTokenizer(br.readLine());
}
N = Integer.parseInt(st.nextToken());
L = Integer.parseInt(st.nextToken());
coordinates = new ArrayList<>();
for(int i = 0; i < N; i++) {
st = new StringTokenizer(br.readLine());
coordinates.add(new Coordinate(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken())));
}
double left = 0;
double right = Double.MAX_VALUE;
double answer = 0;
while(true) {
double mid = (left + right) / 2;
boolean working = works(mid);
if(working) {
answer = mid;
left = mid;
} else {
right = mid;
}
if(isEqual(left, right)) {
break;
}
}
out.print(answer);
out.close();
}
static boolean works(double radius) {
ArrayList<Intercept> intercepts = new ArrayList<>();
int id = 0;
for(Coordinate c : coordinates) {
double[] theseInter = getIntercepts(c.x, c.y, radius);
if(theseInter.length == 2) {
intercepts.add(new Intercept(Math.min(theseInter[0], theseInter[1]), 1, id));
intercepts.add(new Intercept(Math.max(theseInter[0], theseInter[1]), 2, id));
id++;
} else if (theseInter.length == 1) {
intercepts.add(new Intercept(theseInter[0], 0, id));
id++;
}
}
intercepts.sort(new Compare());
int numCircles = 0;
for (Intercept intercept : intercepts) {
if (intercept.x >= 0 && intercept.x <= L && numCircles == 0) {
return true;
}
if (intercept.type == 1) {
numCircles++;
} else if (intercept.type == 2) {
numCircles--;
}
}
return false;
}
static double[] getIntercepts(double k, double h, double radius) {
if(radius * radius - h * h > 0) {
double sqrt = Math.sqrt(radius * radius - h * h);
return new double[] {sqrt + k, -sqrt + k};
} else if (radius * radius - h * h == 0) {
return new double[] {k};
} else {
return new double[] {};
}
}
static boolean isEqual(double one, double two) {
return Math.abs(one - two) <= 0.001;
}
static class Coordinate {
int x;
int y;
public Coordinate(int x, int y) {
this.x = x;
this.y = y;
}
}
static class Intercept {
double x;
int type;
int id;
public Intercept(double x, int t, int id) {
this.x = x;
type = t;
this.id = id;
}
}
static class Compare implements Comparator<Intercept> {
@Override
public int compare(Intercept o1, Intercept o2) {
if(o1.x < o2.x) {
return -1;
} else if (o1.x == o2.x) {
return 0;
}
return 1;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
131 ms |
12564 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
127 ms |
12232 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
140 ms |
12112 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
128 ms |
11900 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
132 ms |
11992 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
130 ms |
12244 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
135 ms |
12312 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
142 ms |
11764 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
136 ms |
12156 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
133 ms |
12100 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
147 ms |
12224 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
148 ms |
12172 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
144 ms |
11928 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
134 ms |
12364 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
136 ms |
12092 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
141 ms |
12112 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
142 ms |
12072 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
127 ms |
12016 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
132 ms |
12236 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
137 ms |
12124 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
145 ms |
11868 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |