exec_outcome
stringclasses
1 value
code_uid
stringlengths
32
32
file_name
stringclasses
111 values
prob_desc_created_at
stringlengths
10
10
prob_desc_description
stringlengths
63
3.8k
prob_desc_memory_limit
stringclasses
18 values
source_code
stringlengths
117
65.5k
lang_cluster
stringclasses
1 value
prob_desc_sample_inputs
stringlengths
2
802
prob_desc_time_limit
stringclasses
27 values
prob_desc_sample_outputs
stringlengths
2
796
prob_desc_notes
nulllengths
4
3k
lang
stringclasses
5 values
prob_desc_input_from
stringclasses
3 values
tags
sequencelengths
0
11
src_uid
stringlengths
32
32
prob_desc_input_spec
stringlengths
28
2.37k
difficulty
int64
-1
3.5k
prob_desc_output_spec
stringlengths
17
1.47k
prob_desc_output_to
stringclasses
3 values
hidden_unit_tests
stringclasses
1 value
PASSED
cc4bd913258499eede67360abafe1602
train_000.jsonl
1267117200
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered. Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
64 megabytes
import java.io.*; import java.util.*; public class Comments implements Runnable { static class Circle { double x; double y; double r; Circle(double x, double y, double r) { this.x = x; this.y = y; this.r = r; } public Circle swapXY() { return new Circle(y, x, r); } } static class SecondOrderCurve { double x2; double y2; double x1; double y1; double free; public SecondOrderCurve(Circle a, Circle b) { x2 = b.r * b.r - a.r * a.r; y2 = x2; x1 = -2 * (b.r * b.r * a.x - a.r * a.r * b.x); y1 = -2 * (b.r * b.r * a.y - a.r * a.r * b.y); free = b.r * b.r * (a.x * a.x + a.y * a.y) - a.r * a.r * (b.x * b.x + b.y * b.y); } SecondOrderCurve(double x2, double y2, double x1, double y1, double free) { this.x2 = x2; this.y2 = y2; this.x1 = x1; this.y1 = y1; this.free = free; } public SecondOrderCurve multiply(double by) { return new SecondOrderCurve(x2 * by, y2 * by, x1 * by, y1 * by, free * by); } public SecondOrderCurve subtract(SecondOrderCurve a) { return new SecondOrderCurve(x2 - a.x2, y2 - a.y2, x1 - a.x1, y1 - a.y1, free - a.free); } public SecondOrderCurve swapXY() { return new SecondOrderCurve(y2, x2, y1, x1, free); } public SecondOrderCurve substituteY(double k, double a) { return new SecondOrderCurve(x2 + y2 * k * k, 0, x1 + y2 * 2 * k * a + y1 * k, 0, free + y2 * a * a + y1 * a); } } private void solve() throws IOException { Circle[] c = new Circle[3]; for (int i = 0; i < 3; ++i) { int x = nextInt(); int y = nextInt(); int r = nextInt(); c[i] = new Circle(x, y, r); } SecondOrderCurve c1 = new SecondOrderCurve(c[0], c[1]); SecondOrderCurve c2 = new SecondOrderCurve(c[0], c[2]); SecondOrderCurve line; SecondOrderCurve check; if (c1.x2 == 0) { line = c1; check = c2; } else if (c2.x2 == 0) { line = c2; check = c1; } else { line = c1.multiply(c2.x2).subtract(c2.multiply(c1.x2)); check = c1; } boolean needSwap = false; if (line.y1 == 0) { needSwap = true; c1 = c1.swapXY(); c2 = c2.swapXY(); line = line.swapXY(); for (int i = 0; i < 3; ++i) c[i] = c[i].swapXY(); } if (line.y1 == 0) throw new RuntimeException(); double k = -line.x1 / line.y1; double a = -line.free / line.y1; SecondOrderCurve quad = check.substituteY(k, a); double mx = Math.max(Math.abs(quad.x2), Math.max(Math.abs(quad.x1), Math.abs(quad.free))); quad.x2 /= mx; quad.x1 /= mx; quad.free /= mx; if (Math.abs(quad.x2) < 1e-12) { if (Math.abs(quad.x1) < 1e-9) { return; } double x = -quad.free / quad.x1; double y = k * x + a; if (needSwap) writer.printf("%.5f %.5f\n", y, x); else { writer.printf("%.5f %.5f\n", x, y); } } else { double d = quad.x1 * quad.x1 - 4 * quad.x2 * quad.free; if (d >= -1e-12 && d < 0) d = 0; if (d < 0) return; double x1 = (-quad.x1 + Math.sqrt(d)) / (2 * quad.x2); double x2 = (-quad.x1 - Math.sqrt(d)) / (2 * quad.x2); double y1 = k * x1 + a; double y2 = k * x2 + a; if (Math.hypot(c[0].x - x1, c[0].y - y1) <= Math.hypot(c[0].x - x2, c[0].y - y2)) { if (needSwap) writer.printf("%.5f %.5f\n", y1, x1); else { writer.printf("%.5f %.5f\n", x1, y1); } } else { if (needSwap) writer.printf("%.5f %.5f\n", y2, x2); else { writer.printf("%.5f %.5f\n", x2, y2); } } } } public static void main(String[] args) { Locale.setDefault(Locale.US); new Comments().run(); } BufferedReader reader; StringTokenizer tokenizer; PrintWriter writer; public void run() { try { reader = new BufferedReader(new InputStreamReader(System.in)); tokenizer = null; writer = new PrintWriter(System.out); solve(); reader.close(); writer.close(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } long nextLong() throws IOException { return Long.parseLong(nextToken()); } double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } String nextToken() throws IOException { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } return tokenizer.nextToken(); } }
Java
["0 0 10\n60 0 10\n30 30 10"]
1 second
["30.00000 0.00000"]
null
Java 8
standard input
[ "geometry" ]
9829e1913e64072aadc9df5cddb63573
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x,  y,  r, where (x, y) are the coordinates of the stadium's center ( -  103 ≤ x,  y ≤ 103), and r (1 ≤ r  ≤ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
2,600
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
standard output
PASSED
d1919199d00f776e7cdd2c7f77f34624
train_000.jsonl
1267117200
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered. Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
64 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Collections; import static java.lang.Math.*; import static java.util.Arrays.asList; import static java.util.Comparator.comparing; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); Circle c[] = new Circle[3]; for (int i = 0; i < 3; i++) { String[] f = br.readLine().split(" "); c[i] = new Circle(new double[]{Double.parseDouble(f[0]), Double.parseDouble(f[1])}, Double.parseDouble(f[2])); } Object f1 = getFigure(c[0], c[1]); Object f2 = getFigure(c[0], c[2]); double ps[][] = intersect(f1, f2); if (ps.length == 0) return; double[] xy = Collections.min(asList(ps), comparing(p -> norm(sub(p, c[0].c)))); System.out.printf("%.5f %.5f%n", xy[0], xy[1]); } private static Object getFigure(Circle c1, Circle c2) { if (eq(c1.r, c2.r)) return new Line(mult(add(c1.c, c2.c), 0.5), rot(sub(c1.c, c2.c))); return new Circle(add( mult(c1.c, sqr(c2.r) / (sqr(c2.r) - sqr(c1.r))), mult(c2.c, sqr(c1.r) / (sqr(c1.r) - sqr(c2.r)))), norm(sub(c1.c, c2.c)) * c1.r * c2.r / abs(sqr(c1.r) - sqr(c2.r))); } ///////////////////////////// // Library functions below // ///////////////////////////// private static double[][] intersect(Object f1, Object f2) { if (f1 instanceof Circle && f2 instanceof Circle) { Circle c1 = (Circle) f1; Circle c2 = (Circle) f2; double l = norm(sub(c1.c, c2.c)); if (eq(l, 0)) return new double[][]{}; double x = (1 - sqr(c2.r / l) + sqr(c1.r / l)) / 2; double y = sqr(c1.r / l) - sqr(x); if (le(y, 0)) return new double[][]{}; double xv[] = add(mult(c1.c, 1 - x), mult(c2.c, x)); if (eq(y, 0)) return new double[][]{xv}; y = sqrt(y); double yv[] = mult(rot(sub(c1.c, c2.c)), y); return new double[][]{add(xv, yv), sub(xv, yv)}; } if (f1 instanceof Circle && f2 instanceof Line) return intersect(f2, f1); if (f1 instanceof Line && f2 instanceof Circle) { Line l = (Line) f1; Circle c = (Circle) f2; double[] v = mult(l.v, 1 / norm(l.v)); double[] p = add(l.a, mult(v, dot(sub(c.c, l.a), v))); double d = sqr(c.r) - sqr(norm(sub(c.c, p))); if (le(d, 0)) return new double[][]{}; if (eq(d, 0)) return new double[][]{p}; d = sqrt(d); return new double[][]{add(p, mult(v, d)), add(p, mult(v, -d))}; } if (f1 instanceof Line && f2 instanceof Line) { Line l1 = (Line) f1; Line l2 = (Line) f2; double a = dot(l1.v, rot(l2.v)); if (eq(a, 0)) return new double[][]{}; return new double[][]{add(l1.a, mult(l1.v, dot(sub(l2.a, l1.a), rot(l2.v)) / a))}; } throw new RuntimeException(); } private static double dot(double[] a, double[] b) { return a[0] * b[0] + a[1] * b[1]; } private static double norm(double[] a) { return Math.hypot(a[0], a[1]); } private static double[] rot(double[] a) { return new double[]{-a[1], a[0]}; } private static double[] mult(double[] a, double b) { return new double[]{a[0] * b, a[1] * b}; } private static double[] sub(double[] a, double[] b) { return new double[]{a[0] - b[0], a[1] - b[1]}; } private static double[] add(double[] a, double[] b) { return new double[]{a[0] + b[0], a[1] + b[1]}; } private static double sqr(double t) { return t * t; } private static final double THR = 1e-10; private static boolean le(double a, double b) { return a + THR < b; } private static boolean eq(double a, double b) { return abs(a - b) < THR; } private static class Circle { double[] c; double r; public Circle(double[] c, double r) { this.c = c; this.r = r; } } private static class Line { double[] a, v; public Line(double[] a, double[] v) { this.a = a; this.v = v; } } }
Java
["0 0 10\n60 0 10\n30 30 10"]
1 second
["30.00000 0.00000"]
null
Java 8
standard input
[ "geometry" ]
9829e1913e64072aadc9df5cddb63573
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x,  y,  r, where (x, y) are the coordinates of the stadium's center ( -  103 ≤ x,  y ≤ 103), and r (1 ≤ r  ≤ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
2,600
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
standard output
PASSED
dbd3f672d8f9851cf7469f9698e769c6
train_000.jsonl
1267117200
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered. Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
64 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import static java.lang.Math.max; import static java.lang.Math.sqrt; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); double x[] = new double[3]; double y[] = new double[3]; double r[] = new double[3]; for (int i = 0; i < 3; i++) { String[] f = br.readLine().split(" "); x[i] = Double.parseDouble(f[0]); y[i] = Double.parseDouble(f[1]); r[i] = Double.parseDouble(f[2]); } double c1[] = getCoefs(x[0], y[0], r[0], x[1], y[1], r[1]); double c2[] = getCoefs(x[0], y[0], r[0], x[2], y[2], r[2]); if (zero(c1[0])) { double tmp[] = c1; c1 = c2; c2 = tmp; } if (!zero(c1[0])) { double mult = c2[0] / c1[0]; for (int i = 0; i < 4; i++) c2[i] -= c1[i] * mult; } // assert(zero(c2[0])) boolean xySwap = zero(c2[1]); if (xySwap) { swap(c1, 1, 2); swap(c2, 1, 2); } if (zero(c2[1])) return; // assert(!zero(c2[1])) // x = -c2[2] / c2[1] * y - c2[3] / c2[1] = d * y + e double d = -c2[2] / c2[1]; double e = -c2[3] / c2[1]; // c1[0] * x^2 + c1[0] * y^2 + c1[1] * x + c1[2] * y + c1[3] = 0 // c1[0] * (d^2 + 1) * y^2 + (2 * c1[0] * d * e + c1[1] * d + c1[2]) * y + c1[0] * e^2 + c1[1] * e + c1[3] = 0 // a * y^2 + b * y + c = 0 double a = c1[0] * (sqr(d) + 1); double b = 2 * c1[0] * d * e + c1[1] * d + c1[2]; double c = c1[0] * sqr(e) + c1[1] * e + c1[3]; double ys[]; if (zero(a)) { if (zero(b)) return; ys = new double[]{-c / b, -c / b}; } else { double D = sqr(b) - 4 * a * c; if (D < -1e-10) return; D = sqrt(max(0, D)); ys = new double[]{-(b + D) / 2 / a, -(b - D) / 2 / a}; } double xs[] = new double[2]; double ds[] = new double[2]; for (int i = 0; i < 2; i++) { xs[i] = d * ys[i] + e; ds[i] = sqr(xs[i] - x[0]) + sqr(ys[i] - y[0]); } int ms = ds[0] < ds[1] ? 0 : 1; double xy[] = {xs[ms], ys[ms]}; if (xySwap) swap(xy, 0, 1); System.out.printf("%.5f %.5f%n", xy[0], xy[1]); } // ((x - x1) ^ 2 + (y - y1) ^ 2) / r1 ^ 2 - ((x - x2) ^ 2 + (y - y2) ^ 2) / r2 ^ 2 = 0 // c[0] * x^2 + c[0] * y^2 + c[1] * x + c[2] * y + c[3] = 0 private static double[] getCoefs(double x1, double y1, double r1, double x2, double y2, double r2) { return new double[]{ 1 / sqr(r1) - 1 / sqr(r2), 2 * (x2 / sqr(r2) - x1 / sqr(r1)), 2 * (y2 / sqr(r2) - y1 / sqr(r1)), (sqr(x1) + sqr(y1)) / sqr(r1) - (sqr(x2) + sqr(y2)) / sqr(r2)}; } private static double sqr(double t) { return t * t; } private static boolean zero(double t) { return Math.abs(t) < 1e-10; } private static void swap(double[] a, int i, int j) { double x = a[i]; a[i] = a[j]; a[j] = x; } }
Java
["0 0 10\n60 0 10\n30 30 10"]
1 second
["30.00000 0.00000"]
null
Java 8
standard input
[ "geometry" ]
9829e1913e64072aadc9df5cddb63573
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x,  y,  r, where (x, y) are the coordinates of the stadium's center ( -  103 ≤ x,  y ≤ 103), and r (1 ≤ r  ≤ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
2,600
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
standard output
PASSED
5cd110d142ab60cd92a26e09b8f93dc2
train_000.jsonl
1267117200
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered. Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
64 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import static java.lang.Math.max; import static java.lang.Math.sqrt; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); double x[] = new double[3]; double y[] = new double[3]; double r[] = new double[3]; for (int i = 0; i < 3; i++) { String[] f = br.readLine().split(" "); x[i] = Double.parseDouble(f[0]); y[i] = Double.parseDouble(f[1]); r[i] = Double.parseDouble(f[2]); } double c1[] = getCoefs(x[0], y[0], r[0], x[1], y[1], r[1]); double c2[] = getCoefs(x[0], y[0], r[0], x[2], y[2], r[2]); if (zero(c1[0])) { double tmp[] = c1; c1 = c2; c2 = tmp; } if (!zero(c1[0])) { double mult = c2[0] / c1[0]; for (int i = 0; i < 4; i++) c2[i] -= c1[i] * mult; } // assert(zero(c2[0])) boolean xySwap = zero(c2[1]); if (xySwap) { swap(c1, 1, 2); swap(c2, 1, 2); } // assert(!zero(c2[1])) // x = -c2[2] / c2[1] * y - c2[3] / c2[1] = d * y + e double d = -c2[2] / c2[1]; double e = -c2[3] / c2[1]; // c1[0] * x^2 + c1[0] * y^2 + c1[1] * x + c1[2] * y + c1[3] = 0 // c1[0] * (d^2 + 1) * y^2 + (2 * c1[0] * d * e + c1[1] * d + c1[2]) * y + c1[0] * e^2 + c1[1] * e + c1[3] = 0 // a * y^2 + b * y + c = 0 double a = c1[0] * (sqr(d) + 1); double b = 2 * c1[0] * d * e + c1[1] * d + c1[2]; double c = c1[0] * sqr(e) + c1[1] * e + c1[3]; double ys[]; if (zero(a)) ys = new double[]{-c / b, -c / b}; else { double D = sqr(b) - 4 * a * c; if (D < -1e-10) return; D = sqrt(max(0, D)); ys = new double[]{-(b + D) / 2 / a, -(b - D) / 2 / a}; } double xs[] = new double[2]; double ds[] = new double[2]; for (int i = 0; i < 2; i++) { xs[i] = d * ys[i] + e; ds[i] = sqr(xs[i] - x[0]) + sqr(ys[i] - y[0]); } int ms = ds[0] < ds[1] ? 0 : 1; double xy[] = {xs[ms], ys[ms]}; if (xySwap) swap(xy, 0, 1); System.out.printf("%.5f %.5f%n", xy[0], xy[1]); } // ((x - x1) ^ 2 + (y - y1) ^ 2) / r1 ^ 2 - ((x - x2) ^ 2 + (y - y2) ^ 2) / r2 ^ 2 = 0 // c[0] * x^2 + c[0] * y^2 + c[1] * x + c[2] * y + c[3] = 0 private static double[] getCoefs(double x1, double y1, double r1, double x2, double y2, double r2) { return new double[]{ 1 / sqr(r1) - 1 / sqr(r2), 2 * (x2 / sqr(r2) - x1 / sqr(r1)), 2 * (y2 / sqr(r2) - y1 / sqr(r1)), (sqr(x1) + sqr(y1)) / sqr(r1) - (sqr(x2) + sqr(y2)) / sqr(r2)}; } private static double sqr(double t) { return t * t; } private static boolean zero(double t) { return Math.abs(t) < 1e-10; } private static void swap(double[] a, int i, int j) { double x = a[i]; a[i] = a[j]; a[j] = x; } }
Java
["0 0 10\n60 0 10\n30 30 10"]
1 second
["30.00000 0.00000"]
null
Java 8
standard input
[ "geometry" ]
9829e1913e64072aadc9df5cddb63573
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x,  y,  r, where (x, y) are the coordinates of the stadium's center ( -  103 ≤ x,  y ≤ 103), and r (1 ≤ r  ≤ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
2,600
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
standard output
PASSED
3d7e2291665226311f7c4ab643a866fd
train_000.jsonl
1267117200
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered. Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
64 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import static java.lang.Math.max; import static java.lang.Math.sqrt; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); double x[] = new double[3]; double y[] = new double[3]; double r[] = new double[3]; for (int i = 0; i < 3; i++) { String[] f = br.readLine().split(" "); x[i] = Double.parseDouble(f[0]); y[i] = Double.parseDouble(f[1]); r[i] = Double.parseDouble(f[2]); } double c1[] = getCoefs(x[0], y[0], r[0], x[1], y[1], r[1]); double c2[] = getCoefs(x[0], y[0], r[0], x[2], y[2], r[2]); if (zero(c1[0])) { double tmp[] = c1; c1 = c2; c2 = tmp; } if (!zero(c1[0])) { double mult = c2[0] / c1[0]; for (int i = 0; i < 4; i++) c2[i] -= c1[i] * mult; } // assert(zero(c2[0])) boolean xySwap = zero(c2[1]); if (xySwap) { swap(c1, 1, 2); swap(c2, 1, 2); } // if (zero(c2[1])) // return; // assert(!zero(c2[1])) // x = -c2[2] / c2[1] * y - c2[3] / c2[1] = d * y + e double d = -c2[2] / c2[1]; double e = -c2[3] / c2[1]; // c1[0] * x^2 + c1[0] * y^2 + c1[1] * x + c1[2] * y + c1[3] = 0 // c1[0] * (d^2 + 1) * y^2 + (2 * c1[0] * d * e + c1[1] * d + c1[2]) * y + c1[0] * e^2 + c1[1] * e + c1[3] = 0 // a * y^2 + b * y + c = 0 double a = c1[0] * (sqr(d) + 1); double b = 2 * c1[0] * d * e + c1[1] * d + c1[2]; double c = c1[0] * sqr(e) + c1[1] * e + c1[3]; double ys[]; if (zero(a)) { // if (zero(b)) // return; ys = new double[]{-c / b, -c / b}; } else { double D = sqr(b) - 4 * a * c; if (D < -1e-10) return; D = sqrt(max(0, D)); ys = new double[]{-(b + D) / 2 / a, -(b - D) / 2 / a}; } double xs[] = new double[2]; double ds[] = new double[2]; for (int i = 0; i < 2; i++) { xs[i] = d * ys[i] + e; ds[i] = sqr(xs[i] - x[0]) + sqr(ys[i] - y[0]); } int ms = ds[0] < ds[1] ? 0 : 1; double xy[] = {xs[ms], ys[ms]}; if (xySwap) swap(xy, 0, 1); System.out.printf("%.5f %.5f%n", xy[0], xy[1]); } // ((x - x1) ^ 2 + (y - y1) ^ 2) / r1 ^ 2 - ((x - x2) ^ 2 + (y - y2) ^ 2) / r2 ^ 2 = 0 // c[0] * x^2 + c[0] * y^2 + c[1] * x + c[2] * y + c[3] = 0 private static double[] getCoefs(double x1, double y1, double r1, double x2, double y2, double r2) { return new double[]{ 1 / sqr(r1) - 1 / sqr(r2), 2 * (x2 / sqr(r2) - x1 / sqr(r1)), 2 * (y2 / sqr(r2) - y1 / sqr(r1)), (sqr(x1) + sqr(y1)) / sqr(r1) - (sqr(x2) + sqr(y2)) / sqr(r2)}; } private static double sqr(double t) { return t * t; } private static boolean zero(double t) { return Math.abs(t) < 1e-10; } private static void swap(double[] a, int i, int j) { double x = a[i]; a[i] = a[j]; a[j] = x; } }
Java
["0 0 10\n60 0 10\n30 30 10"]
1 second
["30.00000 0.00000"]
null
Java 8
standard input
[ "geometry" ]
9829e1913e64072aadc9df5cddb63573
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x,  y,  r, where (x, y) are the coordinates of the stadium's center ( -  103 ≤ x,  y ≤ 103), and r (1 ≤ r  ≤ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
2,600
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
standard output
PASSED
d8a3e42fa33516709cdc634c5586356c
train_000.jsonl
1267117200
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered. Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
64 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Collections; import static java.lang.Math.*; import static java.util.Arrays.asList; import static java.util.Comparator.comparing; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); Circle c[] = new Circle[3]; for (int i = 0; i < 3; i++) { String[] f = br.readLine().split(" "); c[i] = new Circle(new double[]{Double.parseDouble(f[0]), Double.parseDouble(f[1])}, Double.parseDouble(f[2])); } Object f1 = getFigure(c[0], c[1]); Object f2 = getFigure(c[0], c[2]); double ps[][] = intersect(f1, f2); if (ps.length == 0) return; double[] xy = Collections.min(asList(ps), comparing(p -> norm(sub(p, c[0].c)))); System.out.printf("%.5f %.5f%n", xy[0], xy[1]); } private static Object getFigure(Circle c1, Circle c2) { double[] d = sub(c2.c, c1.c); if (eq(c1.r, c2.r)) return new Line(add(c1.c, mult(d, 0.5)), rot(d)); double e1 = c1.r / (c1.r + c2.r); double e2 = -c1.r / (-c1.r + c2.r); return new Circle(add(c1.c, mult(d, (e1 + e2) / 2)), norm(d) * abs(e2 - e1) / 2); } ///////////////////////////// // Library functions below // ///////////////////////////// private static double[][] intersect(Object f1, Object f2) { if (f1 instanceof Circle && f2 instanceof Circle) { Circle c1 = (Circle) f1; Circle c2 = (Circle) f2; double l = norm(sub(c1.c, c2.c)); if (eq(l, 0)) return new double[][]{}; double x = (1 - sqr(c2.r / l) + sqr(c1.r / l)) / 2; double y = sqr(c1.r / l) - sqr(x); if (le(y, 0)) return new double[][]{}; double xv[] = add(mult(c1.c, 1 - x), mult(c2.c, x)); if (eq(y, 0)) return new double[][]{xv}; y = sqrt(y); double yv[] = mult(rot(sub(c1.c, c2.c)), y); return new double[][]{add(xv, yv), sub(xv, yv)}; } if (f1 instanceof Circle && f2 instanceof Line) return intersect(f2, f1); if (f1 instanceof Line && f2 instanceof Circle) { Line l = (Line) f1; Circle c = (Circle) f2; double[] v = mult(l.v, 1 / norm(l.v)); double[] p = add(l.a, mult(v, dot(sub(c.c, l.a), v))); double d = sqr(c.r) - sqr(norm(sub(c.c, p))); if (le(d, 0)) return new double[][]{}; if (eq(d, 0)) return new double[][]{p}; d = sqrt(d); return new double[][]{add(p, mult(v, d)), add(p, mult(v, -d))}; } if (f1 instanceof Line && f2 instanceof Line) { Line l1 = (Line) f1; Line l2 = (Line) f2; double a = dot(l1.v, rot(l2.v)); if (eq(a, 0)) return new double[][]{}; return new double[][]{add(l1.a, mult(l1.v, dot(sub(l2.a, l1.a), rot(l2.v)) / a))}; } throw new RuntimeException(); } private static double dot(double[] a, double[] b) { return a[0] * b[0] + a[1] * b[1]; } private static double norm(double[] a) { return Math.hypot(a[0], a[1]); } private static double[] rot(double[] a) { return new double[]{-a[1], a[0]}; } private static double[] mult(double[] a, double b) { return new double[]{a[0] * b, a[1] * b}; } private static double[] sub(double[] a, double[] b) { return new double[]{a[0] - b[0], a[1] - b[1]}; } private static double[] add(double[] a, double[] b) { return new double[]{a[0] + b[0], a[1] + b[1]}; } private static double sqr(double t) { return t * t; } private static final double THR = 1e-10; private static boolean le(double a, double b) { return a + THR < b; } private static boolean eq(double a, double b) { return abs(a - b) < THR; } private static class Circle { double[] c; double r; public Circle(double[] c, double r) { this.c = c; this.r = r; } } private static class Line { double[] a, v; public Line(double[] a, double[] v) { this.a = a; this.v = v; } } }
Java
["0 0 10\n60 0 10\n30 30 10"]
1 second
["30.00000 0.00000"]
null
Java 8
standard input
[ "geometry" ]
9829e1913e64072aadc9df5cddb63573
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x,  y,  r, where (x, y) are the coordinates of the stadium's center ( -  103 ≤ x,  y ≤ 103), and r (1 ≤ r  ≤ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
2,600
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
standard output
PASSED
32bb9539cbdb45e1a19c7cadf06da816
train_000.jsonl
1267117200
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered. Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
64 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import static java.lang.Math.max; import static java.lang.Math.sqrt; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); double x[] = new double[3]; double y[] = new double[3]; double r[] = new double[3]; for (int i = 0; i < 3; i++) { String[] f = br.readLine().split(" "); x[i] = Double.parseDouble(f[0]); y[i] = Double.parseDouble(f[1]); r[i] = Double.parseDouble(f[2]); } double c1[] = getCoefs(x[0], y[0], r[0], x[1], y[1], r[1]); double c2[] = getCoefs(x[0], y[0], r[0], x[2], y[2], r[2]); if (zero(c1[0])) { double tmp[] = c1; c1 = c2; c2 = tmp; } if (!zero(c1[0])) { double mult = c2[0] / c1[0]; for (int i = 0; i < 4; i++) c2[i] -= c1[i] * mult; } // assert(zero(c2[0])) boolean xySwap = zero(c2[1]); if (xySwap) { swap(c1, 1, 2); swap(c2, 1, 2); } // if (zero(c2[1])) // return; // assert(!zero(c2[1])) // x = -c2[2] / c2[1] * y - c2[3] / c2[1] = d * y + e double d = -c2[2] / c2[1]; double e = -c2[3] / c2[1]; // c1[0] * x^2 + c1[0] * y^2 + c1[1] * x + c1[2] * y + c1[3] = 0 // c1[0] * (d^2 + 1) * y^2 + (2 * c1[0] * d * e + c1[1] * d + c1[2]) * y + c1[0] * e^2 + c1[1] * e + c1[3] = 0 // a * y^2 + b * y + c = 0 double a = c1[0] * (sqr(d) + 1); double b = 2 * c1[0] * d * e + c1[1] * d + c1[2]; double c = c1[0] * sqr(e) + c1[1] * e + c1[3]; double ys[]; if (zero(a)) { if (zero(b)) return; ys = new double[]{-c / b, -c / b}; } else { double D = sqr(b) - 4 * a * c; if (D < -1e-10) return; D = sqrt(max(0, D)); ys = new double[]{-(b + D) / 2 / a, -(b - D) / 2 / a}; } double xs[] = new double[2]; double ds[] = new double[2]; for (int i = 0; i < 2; i++) { xs[i] = d * ys[i] + e; ds[i] = sqr(xs[i] - x[0]) + sqr(ys[i] - y[0]); } int ms = ds[0] < ds[1] ? 0 : 1; double xy[] = {xs[ms], ys[ms]}; if (xySwap) swap(xy, 0, 1); System.out.printf("%.5f %.5f%n", xy[0], xy[1]); } // ((x - x1) ^ 2 + (y - y1) ^ 2) / r1 ^ 2 - ((x - x2) ^ 2 + (y - y2) ^ 2) / r2 ^ 2 = 0 // c[0] * x^2 + c[0] * y^2 + c[1] * x + c[2] * y + c[3] = 0 private static double[] getCoefs(double x1, double y1, double r1, double x2, double y2, double r2) { return new double[]{ 1 / sqr(r1) - 1 / sqr(r2), 2 * (x2 / sqr(r2) - x1 / sqr(r1)), 2 * (y2 / sqr(r2) - y1 / sqr(r1)), (sqr(x1) + sqr(y1)) / sqr(r1) - (sqr(x2) + sqr(y2)) / sqr(r2)}; } private static double sqr(double t) { return t * t; } private static boolean zero(double t) { return Math.abs(t) < 1e-10; } private static void swap(double[] a, int i, int j) { double x = a[i]; a[i] = a[j]; a[j] = x; } }
Java
["0 0 10\n60 0 10\n30 30 10"]
1 second
["30.00000 0.00000"]
null
Java 8
standard input
[ "geometry" ]
9829e1913e64072aadc9df5cddb63573
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x,  y,  r, where (x, y) are the coordinates of the stadium's center ( -  103 ≤ x,  y ≤ 103), and r (1 ≤ r  ≤ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
2,600
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
standard output
PASSED
484b157955d6d903d36c67350d8c076e
train_000.jsonl
1267117200
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered. Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
64 megabytes
import java.text.DecimalFormat; import java.util.Scanner; public class Main2 { class circle{ double x,y; double r; } circle[] circ = new circle[3]; public double dis(double x, double y, circle c){ return Math.sqrt((x-c.x)*(x-c.x) + (y-c.y)*(y-c.y)); } public double cost(double x, double y){ double[] ang = new double[3]; for(int i=0;i<3;i++) ang[i] = dis(x , y , circ[i]) / circ[i].r; double[] d = new double[3]; for(int i=0;i<3;i++) d[i] = ang[i] - ang[(i+1)%3]; return d[0]*d[0]+d[1]*d[1]+d[2]*d[2]; } public void run(){ Scanner sc = new Scanner(System.in); for(int i=0;i<3;i++){ circ[i] = new circle(); circ[i].x = sc.nextDouble(); circ[i].y = sc.nextDouble(); circ[i].r = sc.nextDouble(); } // Get Center double center_x = 0; double center_y = 0; for(int i=0;i<3;i++){ center_x += circ[i].x / 3; center_y += circ[i].y / 3; } double t = 1.0; // ? while(t>1e-5){ boolean flag = false; if(cost(center_x+t, center_y)<cost(center_x, center_y)){ center_x+=t; flag=true; } else if(cost(center_x, center_y+t)<cost(center_x, center_y)){ center_y+=t; flag=true; } else if(cost(center_x-t, center_y)<cost(center_x, center_y)){ center_x-=t; flag=true; } else if(cost(center_x, center_y-t)<cost(center_x, center_y)){ center_y-=t; flag=true; } if(!flag) t*=0.5; } DecimalFormat df = new DecimalFormat("0.00000"); if(Math.abs(cost(center_x, center_y)) < 1e-5) System.out.println(df.format(center_x) + " " + df.format(center_y)); } public static void main(String[] args) { new Main2().run(); } }
Java
["0 0 10\n60 0 10\n30 30 10"]
1 second
["30.00000 0.00000"]
null
Java 8
standard input
[ "geometry" ]
9829e1913e64072aadc9df5cddb63573
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x,  y,  r, where (x, y) are the coordinates of the stadium's center ( -  103 ≤ x,  y ≤ 103), and r (1 ≤ r  ≤ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
2,600
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
standard output
PASSED
d5fe5b35f07924a21fb3e39562986e95
train_000.jsonl
1267117200
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered. Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
64 megabytes
import java.util.*; public class Main { static Point[] cs; static double[] rs; static double fit(Point p) { double[] asist = new double[3]; for (int i = 0; i < 3; i++) { asist[i] = ang(p, cs[i], rs[i]); } return (asist[0] - asist[1]) * (asist[0] - asist[1]) + (asist[0] - asist[2]) * (asist[0] - asist[2]) + (asist[1] - asist[2]) * (asist[1] - asist[2]); } static double ang(Point p, Point c, double r) { return p.dist(c) / r; } static class Point { double x; double y; public Point(double x, double y) { this.x = x; this.y = y; } static double cross(Point pt1, Point pt2) { return pt1.x * pt2.y - pt1.y * pt2.x; } double ort(Point pt) { return pt.y - pt.x; } double dist(Point p) { return Math.sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y)); } } public static void main(String[] args) { Scanner input = new Scanner(System.in); cs = new Point[3]; rs = new double[3]; for (int i = 0; i < 3; i++) { cs[i] = new Point(input.nextInt(), input.nextInt()); rs[i] = input.nextInt(); } Point start = new Point((cs[0].x + cs[1].x + cs[2].x) / 3, (cs[0].y + cs[1].y + cs[2].y) / 3); double change = 10; int[] dx = new int[]{0, 1, 0, -1}; int[] dy = new int[]{1, 0, -1, 0}; while (change > 1e-9) { boolean check = false; for (int k = 0; k < 4; k++) { double nx = start.x + dx[k] * change; double ny = start.y + dy[k] * change; Point next = new Point(nx, ny); if (fit(next) < fit(start)) { start = next; check = true; break; } } if (!check) change /= 2; } if (fit(start) < 1e-6) System.out.println(start.x + " " + start.y); } }
Java
["0 0 10\n60 0 10\n30 30 10"]
1 second
["30.00000 0.00000"]
null
Java 8
standard input
[ "geometry" ]
9829e1913e64072aadc9df5cddb63573
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x,  y,  r, where (x, y) are the coordinates of the stadium's center ( -  103 ≤ x,  y ≤ 103), and r (1 ≤ r  ≤ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
2,600
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
standard output
PASSED
20ab5f78ebd014335ad2354169ecd1ae
train_000.jsonl
1267117200
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered. Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
64 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.*; import static java.lang.Math.*; import static java.lang.String.format; public class CF002C { private static class Point { double x; double y; public Point(double x, double y) { this.x = x; this.y = y; } } private static class Circle extends Point { double r; public Circle(double x, double y, double r) { super(x, y); this.r = r; } } private static Point[] getCircleCircleIntersections( double cx0, double cy0, double radius0, double cx1, double cy1, double radius1) { double dx = cx0 - cx1; double dy = cy0 - cy1; double dist = sqrt(dx * dx + dy * dy); // Find the distance between the centers. if (dist > radius0 + radius1) { return new Point[]{}; // No solutions, the circles are too far apart. } else if (dist < abs(radius0 - radius1)) { return new Point[]{}; // No solutions, one circle contains the other. } else if ((dist == 0) && (radius0 == radius1)) { return new Point[]{}; // No solutions, the circles coincide. } else { // Find a and h. double a = (radius0 * radius0 - radius1 * radius1 + dist * dist) / (2 * dist); double h = sqrt(radius0 * radius0 - a * a); // Find P2. double cx2 = cx0 + a * (cx1 - cx0) / dist; double cy2 = cy0 + a * (cy1 - cy0) / dist; return new Point[]{ new Point(cx2 + h * (cy1 - cy0) / dist, cy2 - h * (cx1 - cx0) / dist), new Point(cx2 - h * (cy1 - cy0) / dist, cy2 + h * (cx1 - cx0) / dist) }; } } private static Point[] getLineCircleIntersections( double cx, double cy, double radius, Point point1, Point point2) { double dx = point2.x - point1.x; double dy = point2.y - point1.y; double A = dx * dx + dy * dy; double B = 2 * (dx * (point1.x - cx) + dy * (point1.y - cy)); double C = (point1.x - cx) * (point1.x - cx) + (point1.y - cy) * (point1.y - cy) - radius * radius; double det = B * B - 4 * A * C; if ((A <= 0.0000001) || (det < 0)) { return new Point[]{}; // No real solutions. } else { // Two solutions. double t = (-B + sqrt(det)) / (2 * A); Point intersection1 = new Point(point1.x + t * dx, point1.y + t * dy); t = (-B - sqrt(det)) / (2 * A); Point intersection2 = new Point(point1.x + t * dx, point1.y + t * dy); return new Point[]{intersection1, intersection2}; } } private static Point getLinesIntersection(Point p1, Point p2, Point p3, Point p4) { double dx12 = p2.x - p1.x; double dy12 = p2.y - p1.y; double dx34 = p4.x - p3.x; double dy34 = p4.y - p3.y; double t1 = ((p1.x - p3.x) * dy34 + (p3.y - p1.y) * dx34) / (dy12 * dx34 - dx12 * dy34); if (Double.isInfinite(t1)) { return null; } return new Point(p1.x + dx12 * t1, p1.y + dy12 * t1); } private static Point getPerpendicularVector(Point v) { return new Point(-v.y, v.x); } private static Point getMiddle(Point a, Point b) { return new Point(a.x + 0.5 * (b.x - a.x), a.y + 0.5 * (b.y - a.y)); } private static Point[] getBisect(Point a, Point b) { Point lp1 = getMiddle(a, b); Point perpend1 = getPerpendicularVector(new Point(b.x - a.x, b.y - a.y)); Point lp2 = new Point(lp1.x + perpend1.x, lp1.y + perpend1.y); return new Point[]{lp1, lp2}; } private static Circle getSameAngle(Circle p1, Circle p2) { double RS1 = p1.r * p1.r; double RS2 = p2.r * p2.r; double t = (RS2 * p1.x - RS1 * p2.x) / (RS2 - RS1); double u = (RS2 * p1.y - RS1 * p2.y) / (RS2 - RS1); double RS = (RS1 * p2.x * p2.x - RS2 * p1.x * p1.x)/ (RS2 - RS1) + (RS1 * p2.y * p2.y - RS2 * p1.y * p1.y)/ (RS2 - RS1) + t*t + u*u; return new Circle(t, u, sqrt(RS)); } private static double dist(Point a, Point b) { return sqrt(pow(a.x-b.x, 2) + pow(a.y-b.y, 2)); } private static Point closest(Point[] ps, Point p) { double minDist = dist(ps[0], p); Point closest = ps[0]; for (int i = 1; i < ps.length; i++) { double dist = dist(ps[i], p); if (minDist > dist) { minDist = dist; closest = ps[i]; } } return closest; } private static Point solveForTwoLines(Circle p1, Circle p2, Circle p3) { Point[] segment1 = getBisect(p1, p2); Point[] segment2 = getBisect(p2, p3); return getLinesIntersection(segment1[0], segment1[1], segment2[0], segment2[1]); } private static Point solveForLineAndCircle(Circle p1, Circle p2, Circle p3) { Point[] segment = getBisect(p1, p2); Circle c = getSameAngle(p2, p3); Point[] inters = getLineCircleIntersections(c.x, c.y, c.r, segment[0], segment[1]); if (inters.length == 0) return null; return closest(inters, p1); } private static Point solveForTwoCircles(Circle p1, Circle p2, Circle p3) { Circle c1 = getSameAngle(p1, p2); Circle c2 = getSameAngle(p2, p3); Point[] inters = getCircleCircleIntersections(c1.x, c1.y, c1.r, c2.x, c2.y, c2.r); if (inters.length == 0) return null; return closest(inters, p1); } public static void main(String[] args) { Scanner scanner = new Scanner(new BufferedReader(new InputStreamReader(System.in))); Circle p1 = new Circle(scanner.nextInt(), scanner.nextInt(), scanner.nextInt()); Circle p2 = new Circle(scanner.nextInt(), scanner.nextInt(), scanner.nextInt()); Circle p3 = new Circle(scanner.nextInt(), scanner.nextInt(), scanner.nextInt()); Point intersect; if (p1.r == p2.r && p2.r == p3.r) { intersect = solveForTwoLines(p1, p2, p3); } else if (p1.r == p2.r) { intersect = solveForLineAndCircle(p1, p2, p3); } else if (p1.r == p3.r){ intersect = solveForLineAndCircle(p1, p3, p2); } else if (p2.r == p3.r){ intersect = solveForLineAndCircle(p2, p3, p1); } else { intersect = solveForTwoCircles(p1, p2, p3); } if (intersect == null) return; System.out.println(format("%.5f %.5f", intersect.x, intersect.y)); } }
Java
["0 0 10\n60 0 10\n30 30 10"]
1 second
["30.00000 0.00000"]
null
Java 8
standard input
[ "geometry" ]
9829e1913e64072aadc9df5cddb63573
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x,  y,  r, where (x, y) are the coordinates of the stadium's center ( -  103 ≤ x,  y ≤ 103), and r (1 ≤ r  ≤ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
2,600
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
standard output
PASSED
acd005a428978dcbd582ad264898421a
train_000.jsonl
1267117200
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered. Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
64 megabytes
import java.util.Scanner; // 模拟退火 public class P2C { private static int[][] p = new int[3][3]; public static void main(String[] args) { Scanner sc = new Scanner(System.in); double x = 0.0, y = 0.0; for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { p[i][j] = sc.nextInt(); } x += p[i][0]; y += p[i][1]; } x /= 3; y /= 3; double step = 1.0; while (step > 1e-6) { double d = deviation(x, y); if (deviation(x + step, y) < d) { x += step; } else if (deviation(x - step, y) < d) { x -= step; } else if (deviation(x, y + step) < d) { y += step; } else if (deviation(x, y - step) < d) { y -= step; } else { step *= 0.7; } } if (deviation(x, y) < 1e-5) { System.out.println(String.format("%.5f %.5f", x, y)); } } private static double deviation(double x, double y) { double sum = 0.0; double[] arr = new double[3]; for (int i = 0; i < 3; ++i) { arr[i] = Math.sqrt(square(p[i][0] - x) + square(p[i][1] - y)) / p[i][2]; } for (int i = 0; i < 3; ++i) { sum += square(arr[(i + 1) % 3] - arr[i]); } return sum; } private static double square(double x) { return x * x; } }
Java
["0 0 10\n60 0 10\n30 30 10"]
1 second
["30.00000 0.00000"]
null
Java 8
standard input
[ "geometry" ]
9829e1913e64072aadc9df5cddb63573
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x,  y,  r, where (x, y) are the coordinates of the stadium's center ( -  103 ≤ x,  y ≤ 103), and r (1 ≤ r  ≤ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
2,600
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
standard output
PASSED
947c69e36031e26d8252f44fffc5b0af
train_000.jsonl
1267117200
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered. Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
64 megabytes
import java.util.*; import java.io.*; import java.awt.Point; import java.math.BigDecimal; import java.math.BigInteger; import static java.lang.Math.*; // Solution is at the bottom of code public class C implements Runnable{ final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null; BufferedReader in; OutputWriter out; StringTokenizer tok = new StringTokenizer(""); public static void main(String[] args){ new Thread(null, new C(), "", 128 * (1L << 20)).start(); } ///////////////////////////////////////////////////////////////////// void init() throws FileNotFoundException{ Locale.setDefault(Locale.US); if (ONLINE_JUDGE){ in = new BufferedReader(new InputStreamReader(System.in)); out = new OutputWriter(System.out); }else{ in = new BufferedReader(new FileReader("input.txt")); out = new OutputWriter("output.txt"); } } //////////////////////////////////////////////////////////////// long timeBegin, timeEnd; void time(){ timeEnd = System.currentTimeMillis(); System.err.println("Time = " + (timeEnd - timeBegin)); } void debug(Object... objects){ if (ONLINE_JUDGE){ for (Object o: objects){ System.err.println(o.toString()); } } } ///////////////////////////////////////////////////////////////////// public void run(){ try{ timeBegin = System.currentTimeMillis(); Locale.setDefault(Locale.US); init(); solve(); out.close(); time(); }catch (Exception e){ e.printStackTrace(System.err); System.exit(-1); } } ///////////////////////////////////////////////////////////////////// String delim = " "; String readString() throws IOException{ while(!tok.hasMoreTokens()){ try{ tok = new StringTokenizer(in.readLine()); }catch (Exception e){ return null; } } return tok.nextToken(delim); } String readLine() throws IOException{ return in.readLine(); } ///////////////////////////////////////////////////////////////// final char NOT_A_SYMBOL = '\0'; char readChar() throws IOException{ int intValue = in.read(); if (intValue == -1){ return NOT_A_SYMBOL; } return (char) intValue; } char[] readCharArray() throws IOException{ return readLine().toCharArray(); } ///////////////////////////////////////////////////////////////// int readInt() throws IOException { return Integer.parseInt(readString()); } int[] readIntArray(int size) throws IOException { int[] array = new int[size]; for (int index = 0; index < size; ++index){ array[index] = readInt(); } return array; } int[] readSortedIntArray(int size) throws IOException { Integer[] array = new Integer[size]; for (int index = 0; index < size; ++index) { array[index] = readInt(); } Arrays.sort(array); int[] sortedArray = new int[size]; for (int index = 0; index < size; ++index) { sortedArray[index] = array[index]; } return sortedArray; } int[] readIntArrayWithDecrease(int size) throws IOException { int[] array = readIntArray(size); for (int i = 0; i < size; ++i) { array[i]--; } return array; } /////////////////////////////////////////////////////////////////// int[][] readIntMatrix(int rowsCount, int columnsCount) throws IOException { int[][] matrix = new int[rowsCount][]; for (int rowIndex = 0; rowIndex < rowsCount; ++rowIndex) { matrix[rowIndex] = readIntArray(columnsCount); } return matrix; } int[][] readIntMatrixWithDecrease(int rowsCount, int columnsCount) throws IOException { int[][] matrix = new int[rowsCount][]; for (int rowIndex = 0; rowIndex < rowsCount; ++rowIndex) { matrix[rowIndex] = readIntArrayWithDecrease(columnsCount); } return matrix; } /////////////////////////////////////////////////////////////////// long readLong() throws IOException{ return Long.parseLong(readString()); } long[] readLongArray(int size) throws IOException{ long[] array = new long[size]; for (int index = 0; index < size; ++index){ array[index] = readLong(); } return array; } //////////////////////////////////////////////////////////////////// double readDouble() throws IOException{ return Double.parseDouble(readString()); } double[] readDoubleArray(int size) throws IOException{ double[] array = new double[size]; for (int index = 0; index < size; ++index){ array[index] = readDouble(); } return array; } //////////////////////////////////////////////////////////////////// BigInteger readBigInteger() throws IOException { return new BigInteger(readString()); } BigDecimal readBigDecimal() throws IOException { return new BigDecimal(readString()); } ///////////////////////////////////////////////////////////////////// Point readPoint() throws IOException{ int x = readInt(); int y = readInt(); return new Point(x, y); } Point[] readPointArray(int size) throws IOException{ Point[] array = new Point[size]; for (int index = 0; index < size; ++index){ array[index] = readPoint(); } return array; } ///////////////////////////////////////////////////////////////////// List<Integer>[] readGraph(int vertexNumber, int edgeNumber) throws IOException{ @SuppressWarnings("unchecked") List<Integer>[] graph = new List[vertexNumber]; for (int index = 0; index < vertexNumber; ++index){ graph[index] = new ArrayList<Integer>(); } while (edgeNumber-- > 0){ int from = readInt() - 1; int to = readInt() - 1; graph[from].add(to); graph[to].add(from); } return graph; } ///////////////////////////////////////////////////////////////////// static class IntIndexPair { static Comparator<IntIndexPair> increaseComparator = new Comparator<C.IntIndexPair>() { @Override public int compare(IntIndexPair indexPair1, IntIndexPair indexPair2) { int value1 = indexPair1.value; int value2 = indexPair2.value; if (value1 != value2) return value1 - value2; int index1 = indexPair1.index; int index2 = indexPair2.index; return index1 - index2; } }; static Comparator<IntIndexPair> decreaseComparator = new Comparator<C.IntIndexPair>() { @Override public int compare(IntIndexPair indexPair1, IntIndexPair indexPair2) { int value1 = indexPair1.value; int value2 = indexPair2.value; if (value1 != value2) return -(value1 - value2); int index1 = indexPair1.index; int index2 = indexPair2.index; return index1 - index2; } }; int value, index; public IntIndexPair(int value, int index) { super(); this.value = value; this.index = index; } public int getRealIndex() { return index + 1; } } IntIndexPair[] readIntIndexArray(int size) throws IOException { IntIndexPair[] array = new IntIndexPair[size]; for (int index = 0; index < size; ++index) { array[index] = new IntIndexPair(readInt(), index); } return array; } ///////////////////////////////////////////////////////////////////// static class OutputWriter extends PrintWriter { final int DEFAULT_PRECISION = 12; protected int precision; protected String format, formatWithSpace; { precision = DEFAULT_PRECISION; format = createFormat(precision); formatWithSpace = format + " "; } public OutputWriter(OutputStream out) { super(out); } public OutputWriter(String fileName) throws FileNotFoundException { super(fileName); } public int getPrecision() { return precision; } public void setPrecision(int precision) { precision = max(0, precision); this.precision = precision; format = createFormat(precision); formatWithSpace = format + " "; } private String createFormat(int precision){ return "%." + precision + "f"; } @Override public void print(double d){ printf(format, d); } public void printWithSpace(double d){ printf(formatWithSpace, d); } public void printAll(double...d){ for (int i = 0; i < d.length - 1; ++i){ printWithSpace(d[i]); } print(d[d.length - 1]); } @Override public void println(double d){ printlnAll(d); } public void printlnAll(double... d){ printAll(d); println(); } } ///////////////////////////////////////////////////////////////////// static final int[][] steps = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; static final int[][] steps8 = { {-1, 0}, {1, 0}, {0, -1}, {0, 1}, {-1, -1}, {1, 1}, {1, -1}, {-1, 1} }; static final boolean check(int index, int lim){ return (0 <= index && index < lim); } ///////////////////////////////////////////////////////////////////// static final boolean checkBit(int mask, int bit){ return (mask & (1 << bit)) != 0; } ///////////////////////////////////////////////////////////////////// static final long getSum(int[] array) { long sum = 0; for (int value: array) { sum += value; } return sum; } static final Point getMinMax(int[] array) { int min = array[0]; int max = array[0]; for (int index = 0, size = array.length; index < size; ++index, ++index) { int value = array[index]; if (index == size - 1) { min = min(min, value); max = max(max, value); } else { int otherValue = array[index + 1]; if (value <= otherValue) { min = min(min, value); max = max(max, otherValue); } else { min = min(min, otherValue); max = max(max, value); } } } return new Point(min, max); } ///////////////////////////////////////////////////////////////////// static class Point { double x, y; public Point(double x, double y) { super(); this.x = x; this.y = y; } public double getDistance(Point other) { return getDistance(other.x, other.y); } public double getDistance(double otherX, double otherY) { double dx = this.x - otherX; double dy = this.y - otherY; return sqrt(dx * dx + dy * dy); } @Override public String toString() { return String.format(Locale.US, "%.5f %.5f", x, y); } } static class Vector extends Point { public Vector(Point start, Point end) { this(end.x - start.x, end.y - start.y); } public Vector(double x, double y) { super(x, y); } public Vector normalize() { double length = getDistance(0, 0); this.x /= length; this.y /= length; return this; } public Vector multiply(double k) { return new Vector(x * k, y * k); } public Point add(Point p) { return new Point(p.x + x, p.y + y); } } static interface Area { Point[] intersect(Area other); } static class Line implements Area { double a, b, c; public Line(Point first, Point second) { this.a = second.y - first.y; this.b = first.x - second.x; this.c = -(first.x * a + first.y * b); normalize(); } public Line(double a, double b, double c) { this.a = a; this.b = b; this.c = c; normalize(); } public void normalize() { double denominator = sqrt(a * a + b * b); this.a /= denominator; this.b /= denominator; this.c /= denominator; } public Line getPerpendicularLine(Point p) { double resultA = -b; double resultB = a; double resultC = -(resultA * p.x + resultB * p.y); return new Line(resultA, resultB, resultC); } private static double det(double a11, double a12, double a21, double a22) { return a11 * a22 - a12 * a21; } @Override public Point[] intersect(Area otherArea) { if (otherArea instanceof Circle) { return otherArea.intersect(this); } else { return this.intersect((Line) otherArea); } } public Point[] intersect(Line other) { double det = det(this.a, this.b, other.a, other.b); double detX = det(-this.c, this.b, -other.c, other.b); double detY = det(this.a, -this.c, other.a, -other.c); Point[] result = new Point[2]; result[0] = result[1] = new Point(detX / det, detY / det); return result; } public double getDistance(Point p) { return a * p.x + b * p.y + c; } } static class Circle implements Area { Point center; double r; public Circle(Point center, double r) { this.center = center; this.r = r; } @Override public Point[] intersect(Area otherArea) { if (otherArea instanceof Circle) { return this.intersect((Circle) otherArea); } else { return this.intersect((Line) otherArea); } } public Point[] intersect(Line line) { double distance = line.getDistance(center); if (distance > r) { return null; } Point mid = new Vector(-line.a, -line.b).normalize().multiply(distance).add(center); double delta = sqrt(r * r - distance * distance); Point[] result = new Point[2]; result[0] = new Vector(-line.b, line.a).normalize().multiply(delta).add(mid); result[1] = new Vector(line.b, -line.a).normalize().multiply(delta).add(mid); return result; } public Point[] intersect(Circle other) { double distance = this.center.getDistance(other.center); if (distance > this.r + other.r) return null; if (this.r > other.r && this.r == distance + other.r) { return other.intersect(this); } if (other.r - this.r > distance + EPS) return null; if (abs(other.r - this.r - distance) < EPS) { } else { } double delta = (this.r * this.r - other.r * other.r) / (2 * distance) + distance / 2; double h = sqrt(this.r * this.r - delta * delta); Vector vector = new Vector(this.center, other.center).normalize(); Point mid = vector.multiply(delta).add(this.center); Point[] result = new Point[2]; result[0] = new Vector(vector.y, -vector.x).normalize().multiply(h).add(mid); result[1] = new Vector(-vector.y, vector.x).normalize().multiply(h).add(mid); return result; } } final static double EPS = 1e-6; void solve() throws IOException { int n = 3; Point[] centers = new Point[n]; int[] r = new int[n]; for (int i = 0; i < n; ++i) { centers[i] = readPoint(); r[i] = readInt(); } Point bestPoint = null; double bestRatio = 0; for (int i = 0, j = 1, k = 2; i < n; ++i, j = (j + 1) % n, k = (k + 1) % n) { Area ijArea = getArea(i, j, centers, r); Area jkArea = getArea(j, k, centers, r); Point[] intersectPoints = ijArea.intersect(jkArea); if (intersectPoints == null) continue; for (Point point : intersectPoints) { double[] distances = new double[n]; for (int index = 0; index < n; ++index) { distances[index] = centers[index].getDistance(point); } boolean correct = true; double ratio = r[0] / distances[0]; for (int index = 0; index < n; ++index) { double curRatio = r[index] / distances[index]; correct &= (abs(curRatio - ratio) < EPS); } if (correct && ratio >= bestRatio) { bestPoint = point; bestRatio = ratio; } } } if (bestPoint != null) { out.println(bestPoint); } } Area getArea(int i, int j, Point[] centers, int[] r) { Vector vector = new Vector(centers[i], centers[j]).normalize(); double distance = centers[i].getDistance(centers[j]); if (r[i] == r[j]) { Line line = new Line(centers[i], centers[j]); Point mid = vector.multiply(distance / 2).add(centers[i]); return line.getPerpendicularLine(mid); } else { double innerDistance = 1.0 * r[i] / (r[i] + r[j]); double outerDistance = innerDistance / (2 * innerDistance - 1); innerDistance *= distance; outerDistance *= distance; Point innerPoint = vector.multiply(innerDistance).add(centers[i]); Point outerPoint = vector.multiply(outerDistance).add(centers[i]); Vector diameterVector = new Vector(innerPoint, outerPoint).normalize(); double radius = innerPoint.getDistance(outerPoint) / 2; Point center = diameterVector.multiply(radius).add(innerPoint); return new Circle(center, radius); } } }
Java
["0 0 10\n60 0 10\n30 30 10"]
1 second
["30.00000 0.00000"]
null
Java 8
standard input
[ "geometry" ]
9829e1913e64072aadc9df5cddb63573
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x,  y,  r, where (x, y) are the coordinates of the stadium's center ( -  103 ≤ x,  y ≤ 103), and r (1 ≤ r  ≤ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
2,600
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
standard output
PASSED
9e8f67fb945993b33a796282e4ecbe3a
train_000.jsonl
1267117200
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered. Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
64 megabytes
import java.io.*; import java.util.*; public class Solution { private BufferedReader in; private PrintWriter out; private StringTokenizer st; public String next() throws Exception { while (st == null || !st.hasMoreElements()) { st = new StringTokenizer(in.readLine()); } return st.nextToken(); } private int nextInt() throws Exception { return Integer.parseInt(next()); } private long nextLong() throws Exception { return Long.parseLong(next()); } private double nextDouble() throws Exception { return Double.parseDouble(next()); } public double sqr(double x) { return x * x; } int[] x = new int[3]; int[] y = new int[3]; int[] r = new int[3]; double[] d = new double[3]; public double error(double dx, double dy) { for (int i = 0; i < 3; i++) { // Distances from point to centers / r d[i] = Math.sqrt(sqr(x[i] - dx) + sqr(y[i] - dy)) / r[i]; } // Value for minimization double s = sqr(d[0] - d[1]) + sqr(d[1] - d[2]) + sqr(d[2] - d[0]); return s; } private void run() throws Exception { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); double dx = 0, dy = 0; for (int i = 0; i < 3; i++) { x[i] = nextInt(); y[i] = nextInt(); r[i] = nextInt(); dx += x[i]; dy += y[i]; } dx /= 3; dy /= 3; double s = 1.0; while (s > 1e-6) { if (error(dx, dy) > error(dx + s, dy)) dx += s; else if (error(dx, dy) > error(dx - s, dy)) dx -= s; else if (error(dx, dy) > error(dx, dy + s)) dy += s; else if (error(dx, dy) > error(dx, dy - s)) dy -= s; else s *= 0.7; } if (error(dx, dy) < 1e-5) { out.printf("%.5f %.5f\n", dx, dy); } out.close(); } public static void main(String[] args) throws Exception { new Solution().run(); } }
Java
["0 0 10\n60 0 10\n30 30 10"]
1 second
["30.00000 0.00000"]
null
Java 8
standard input
[ "geometry" ]
9829e1913e64072aadc9df5cddb63573
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x,  y,  r, where (x, y) are the coordinates of the stadium's center ( -  103 ≤ x,  y ≤ 103), and r (1 ≤ r  ≤ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
2,600
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
standard output
PASSED
721b681ccf3799012d2df800eb58417b
train_000.jsonl
1267117200
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered. Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
64 megabytes
import java.io.*; import java.util.*; public class C2 { FastScanner in; PrintWriter out; int x1, y1, r1, x2, y2, r2, x3, y3, r3; double[] getPoints(double angle) { double R1 = r1 / Math.sin(angle / 2), R2 = r2 / Math.sin(angle / 2), R3 = r3 / Math.sin(angle / 2); double A1 = x1 - x2, B1 = y1 - y2, C1 = (y1 * y1 - y2 * y2 + x1 * x1 - x2 * x2 - R1 * R1 + R2 * R2) / 2; double A2 = x1 - x3, B2 = y1 - y3, C2 = (y1 * y1 - y3 * y3 + x1 * x1 - x3 * x3 - R1 * R1 + R3 * R3) / 2; return new double[]{(C1 * B2 - C2 * B1) / (A1 * B2 - A2 * B1), (A1 * C2 - A2 * C1) / (A1 * B2 - A2 * B1)}; } double calcDifference(double angle) { double R1 = r1 / Math.sin(angle / 2); double[] crd = getPoints(angle); return Math.sqrt((crd[0] - x1) * (crd[0] - x1) + (crd[1] - y1) * (crd[1] - y1)) - R1; } public void run() { try { in = new FastScanner(); out = new PrintWriter(System.out); Locale.setDefault(Locale.US); x1 = in.nextInt(); y1 = in.nextInt(); r1 = in.nextInt(); x2 = in.nextInt(); y2 = in.nextInt(); r2 = in.nextInt(); x3 = in.nextInt(); y3 = in.nextInt(); r3 = in.nextInt(); double L = 0, R = Math.PI; for (int i = 0; i < 1000; i++) { double M1 = (L * 2 + R) / 3, M2 = (L + R * 2) / 3; if (calcDifference(M1) > calcDifference(M2)) L = M1; else R = M2; } R = Math.PI; for (int i = 0; i < 1000; i++) { double M = (L + R) / 2; if (calcDifference(M) < 0) L = M; else R = M; } if (Math.abs(calcDifference(L)) < 1e-5) { double[] ans = getPoints(L); out.format("%.5f %.5f\n", ans[0], ans[1]); } out.close(); } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { new C2().run(); } class FastScanner { BufferedReader reader; StringTokenizer tokenizer; FastScanner() { reader = new BufferedReader(new InputStreamReader(System.in)); } FastScanner(String filename) throws FileNotFoundException { reader = new BufferedReader(new FileReader(filename)); } String nextToken() { if (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { e.printStackTrace(); } } return tokenizer.nextToken(); } int nextInt() { return Integer.parseInt(nextToken()); } long nextLong() { return Long.parseLong(nextToken()); } double nextDouble() { return Double.parseDouble(nextToken()); } } }
Java
["0 0 10\n60 0 10\n30 30 10"]
1 second
["30.00000 0.00000"]
null
Java 8
standard input
[ "geometry" ]
9829e1913e64072aadc9df5cddb63573
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x,  y,  r, where (x, y) are the coordinates of the stadium's center ( -  103 ≤ x,  y ≤ 103), and r (1 ≤ r  ≤ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
2,600
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
standard output
PASSED
4ca6fe52da7d6651178fe913952c5d66
train_000.jsonl
1267117200
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered. Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
64 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); cs = new Point[3]; rs = new double[3]; for (int i = 0; i < 3; i++) { cs[i] = new Point(input.nextInt(), input.nextInt()); rs[i] = input.nextInt(); } Point start = new Point((cs[0].x + cs[1].x + cs[2].x) / 3, (cs[0].y + cs[1].y + cs[2].y) / 3); double change = 10; int[] dx = new int[]{0, 1, 0, -1}; int[] dy = new int[]{1, 0, -1, 0}; while (change > 1e-9) { boolean check = false; for (int k = 0; k < 4; k++) { double nx = start.x + dx[k] * change; double ny = start.y + dy[k] * change; Point next = new Point(nx, ny); if (fit(next) < fit(start)) { start = next; check = true; break; } } if (!check) change /= 2; } if (fit(start) < 1e-6) System.out.println(start.x + " " + start.y); } static Point[] cs; static double[] rs; static double fit(Point p) { double[] asist = new double[3]; for (int i = 0; i < 3; i++) { asist[i] = ang(p, cs[i], rs[i]); } return (asist[0] - asist[1]) * (asist[0] - asist[1]) + (asist[0] - asist[2]) * (asist[0] - asist[2]) + (asist[1] - asist[2]) * (asist[1] - asist[2]); } static double ang(Point p, Point c, double r) { return p.dist(c) / r; } static class Point { double x; double y; public Point(double x, double y) { this.x=x; this.y=y; } static double cross(Point pt1, Point pt2) { return pt1.x*pt2.y-pt1.y*pt2.x; } double ort(Point pt) { return pt.y-pt.x; } double dist(Point p) { return Math.sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y)); } } }
Java
["0 0 10\n60 0 10\n30 30 10"]
1 second
["30.00000 0.00000"]
null
Java 8
standard input
[ "geometry" ]
9829e1913e64072aadc9df5cddb63573
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x,  y,  r, where (x, y) are the coordinates of the stadium's center ( -  103 ≤ x,  y ≤ 103), and r (1 ≤ r  ≤ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
2,600
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
standard output
PASSED
c34cf58dfbe1568315750bfcc8c032c2
train_000.jsonl
1267117200
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered. Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
64 megabytes
import java.util.Scanner; /** * 2c-commentator problem 模拟退火 * 作者:hongyanbo * 时间:2018/3/19 */ public class Main { static Circle[] circles = new Circle[3]; static class Circle{ double x,y,r; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); // 中心点,算法开始的点。 double x =0,y=0; for (int i = 0; i < 3; i++) { Circle circle = new Circle(); circle.x = sc.nextInt(); circle.y = sc.nextInt(); circle.r = sc.nextInt(); x += circle.x /3; y += circle.y /3; circles[i] = circle; } double step = 1.0; // 步长,或者也叫温度 while(step > 1e-6){ boolean flag = true ; double d = deviation(x,y); if(deviation(x+step,y) < d){ x+= step; }else if(deviation(x,y+step) <d){ y += step; }else if(deviation(x-step,y) <d){ x -= step ; }else if(deviation(x,y-step) <d){ y -= step; }else{ step*=0.7; } } if(deviation(x,y) < 1e-5){ System.out.println(String.format("%.5f %.5f",x,y)); } } /** * 计算点到三个角度的方差 * 题目要求 the stadiums should be observed at the same angle * 就是说,方差最后要等于0才行。 */ public static double deviation(double x , double y){ double res = 0.0; //方差 double[] arr = new double[3]; //角度 int i = 0; for (Circle circle : circles) { arr[i] = Math.sqrt(square(circle.x-x)+square(circle.y-y))/circle.r; i++; } for (int k = 0; k < 3; k++) { res += square(arr[k] - arr[(k+1)%3]); } return res; } public static double square(double x){ return x*x;} }
Java
["0 0 10\n60 0 10\n30 30 10"]
1 second
["30.00000 0.00000"]
null
Java 8
standard input
[ "geometry" ]
9829e1913e64072aadc9df5cddb63573
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x,  y,  r, where (x, y) are the coordinates of the stadium's center ( -  103 ≤ x,  y ≤ 103), and r (1 ≤ r  ≤ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
2,600
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
standard output
PASSED
493f399574cec4264d6cd8046da5e45d
train_000.jsonl
1267117200
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered. Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
64 megabytes
import java.io.*; import java.text.*; import java.math.*; import java.util.*; public class Main implements Runnable { final double eps = 1e-5; circle[] stad; double ans_x, ans_y, ans_r; boolean ans_found; void test2(double x, double y, int e ) { double[] rr = new double[3]; for (int i = 0; i < 3; i++) { double r = (x - stad[i].x) * (x - stad[i].x) + (y - stad[i].y) * (y - stad[i].y); rr[i] = Math.sqrt(r); } { double[] t = new double[3]; for (int i=0; i<3; i++) t[i] = rr[i]/stad[i].r; for (int i=0; i<3; i++) for (int j=i+1; j<3; j++) if (i!=e && j!=e ) if (Math.abs(t[i]-t[j])>eps) System.out.println("FAIL 2"); } } void test(double x, double y) { double[] rr = new double[3]; for (int i = 0; i < 3; i++) { double r = (x - stad[i].x) * (x - stad[i].x) + (y - stad[i].y) * (y - stad[i].y); if (r < stad[i].r * stad[i].r - eps) return; rr[i] = Math.sqrt(r); } //test2(x, y, -1); if (!ans_found || ans_r > rr[0]) { ans_x = x; ans_y = y; ans_r = rr[0]; ans_found = true; } } public void solve() throws Exception { stad = new circle[3]; ans_found = false; for (int i = 0; i < 3; i++) stad[i] = new circle(iread(), iread(), iread()); line[] lines = new line[2]; circle[] circles = new circle[2]; boolean[] is_line = new boolean[2]; for (int k = 0; k < 2; k++) { int first = 0, second = k + 1; if (stad[first].r == stad[second].r) { is_line[k] = true; double A = stad[second].x - stad[first].x; double B = stad[second].y - stad[first].y; double D = Math.sqrt(A * A + B * B); A /= D; B /= D; double C = -(A * (stad[first].x + stad[second].x) + B * (stad[first].y + stad[second].y)) / 2.0; lines[k] = new line(A, B, C); } else { is_line[k] = false; double r1 = stad[first].r, r2 = stad[second].r; double x1 = stad[first].x, y1 = stad[first].y; double x2 = stad[second].x, y2 = stad[second].y; double X1 = (x1 * r2 + x2 * r1) / (r1 + r2); double Y1 = (y1 * r2 + y2 * r1) / (r1 + r2); double X2 = (-x1 * r2 + x2 * r1) / (r1 - r2); double Y2 = (-y1 * r2 + y2 * r1) / (r1 - r2); double X = (X1 + X2) / 2.0; double Y = (Y1 + Y2) / 2.0; double R = Math.sqrt((X2 - X1) * (X2 - X1) + (Y2 - Y1) * (Y2 - Y1)) / 2.0; circles[k] = new circle(X, Y, R); // test2(X1, Y1, 3-first-second); // test2(X2, Y2, 3-first-second); } } if (is_line[0] && is_line[1]) intersect(lines[0], lines[1]); if (is_line[0] && !is_line[1]) intersect(lines[0], circles[1]); if (!is_line[0] && is_line[1]) intersect(lines[1], circles[0]); if (!is_line[0] && !is_line[1]) intersect(circles[0], circles[1]); if (ans_found) { DecimalFormat df = new DecimalFormat("0.00000"); out.write(df.format(ans_x)+ " "+df.format(ans_y)); } } void intersect(circle u, circle v) { double dx = v.x - u.x, dy = v.y - u.y; double r1 = u.r, r2 = v.r, R = Math.sqrt(dx * dx + dy * dy); dx /= R; dy /= R; if (r1 + r2 < R - eps || r1 + R < r2 - eps || r2 + R < r1 - eps) return; double d1 = (r1 * r1 - r2 * r2 + R * R) / (2 * R); double d2 = Math.sqrt(r1 * r1 - d1 * d1); double X1 = u.x + d1 * dx, Y1 = u.y + d1 * dy; double X2 = -d2 * dy, Y2 = d2 * dx; test(X1 + X2, Y1 + Y2); test(X1 - X2, Y1 - Y2); } void intersect(line u, circle v) { double D = v.x * u.a + v.y * u.b + u.c; if (Math.abs(D) > v.r + eps) return; double D2 = Math.sqrt(v.r * v.r - D * D); double X1 = v.x - D * u.a, Y1 = v.y - D * u.b; double X2 = u.b * D2, Y2 = -u.a * D2; test(X1 + X2, Y1 + Y2); test(X1 - X2, Y1 - Y2); } void intersect(line u, line v) { double D = u.a * v.b - u.b * v.a; if (D < eps) return; double A = -(u.c * v.b - u.b * v.c); double B = -(u.a * v.c - u.c * v.a); test(A / D, B / D); } class line { double a, b, c; public line(double a, double b, double c) { this.a = a; this.b = b; this.c = c; } } class circle { double x, y, r; public circle(double x, double y, double r) { this.x = x; this.y = y; this.r = r; } } public void run() { try{ Locale.setDefault(Locale.US); } catch (Exception e) { } try { in = new BufferedReader(new InputStreamReader(System.in)); out = new BufferedWriter(new OutputStreamWriter(System.out)); solve(); out.flush(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } public int iread() throws Exception { return Integer.parseInt(readword()); } public double dread() throws Exception { return Double.parseDouble(readword()); } public long lread() throws Exception { return Long.parseLong(readword()); } BufferedReader in; BufferedWriter out; public String readword() throws IOException { StringBuilder b = new StringBuilder(); int c; c = in.read(); while (c >= 0 && c <= ' ') c = in.read(); if (c < 0) return ""; while (c > ' ') { b.append((char) c); c = in.read(); } return b.toString(); } public static void main(String[] args) { // Locale.setDefault(Locale.US); new Thread(new Main()).start(); } }
Java
["0 0 10\n60 0 10\n30 30 10"]
1 second
["30.00000 0.00000"]
null
Java 8
standard input
[ "geometry" ]
9829e1913e64072aadc9df5cddb63573
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x,  y,  r, where (x, y) are the coordinates of the stadium's center ( -  103 ≤ x,  y ≤ 103), and r (1 ≤ r  ≤ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
2,600
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
standard output
PASSED
b3e4b3e304afddd51c36c06295c00f16
train_000.jsonl
1267117200
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered. Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
64 megabytes
import java.util.Scanner; public class Solution { public static double distance (double x1, double y1, double x2, double y2) { return Math.sqrt((x2 - x1)*(x2 - x1) + (y2 - y1) * (y2 - y1)); } public static void calculate_line_circle(double a, double b, double c, double x1, double y1, double r, double x_origine, double y_origine) { if (b != 0) { double k = -a/b; double kc = -c/b; double A = 1 +k*k; double B = -2*x1 + 2*k*(kc-y1); double C = x1*x1 + (kc-y1)*(kc-y1)-r*r; double delta = B*B-4*A*C; if (delta == 0) { double x_out = -B/(2*A); double y_out = k*x_out + kc; System.out.println(x_out + " " + y_out); } else if (delta > 0) { double x_out_1 = (-B + Math.sqrt(delta))/(2*A); double y_out_1 = k*(x_out_1) + kc; double x_out_2 = (-B - Math.sqrt(delta))/(2*A); double y_out_2 = k*(x_out_2) + kc; if (distance(x_out_1, y_out_1, x_origine, y_origine) < distance(x_out_2, y_out_2, x_origine, y_origine)) { System.out.println(x_out_1 + " " + y_out_1); } else { System.out.println(x_out_2 + " " + y_out_2); } } } else { double x_out = -c/a; double delta = r*r - (x_out-x1)*(x_out-x1); if(delta == 0) { System.out.println(x_out + " " + y1); } else if (delta > 0) { double y_out_1 = y1 + Math.sqrt(delta); double y_out_2 = y1 - Math.sqrt(delta); if (Math.abs(y_out_1 - y_origine) < Math.abs(y_out_2 - y_origine)) { System.out.println(x_out + " " + y_out_1); } else { System.out.println(x_out + " " + y_out_2); } } } } public static void main(String args[]) { Scanner s = new Scanner(System.in); int x1 = s.nextInt(); int y1 = s.nextInt(); int r1 = s.nextInt(); int x2 = s.nextInt(); int y2 = s.nextInt(); int r2 = s.nextInt(); int x3 = s.nextInt(); int y3 = s.nextInt(); int r3 = s.nextInt(); //circle 12 parameters double x12_inside = 0, y12_inside = 0, x12_outside = 0, y12_outside = 0, x12 = 0, y12 = 0, r12 = 0; //line 12 parameters double x12_mid = 0, y12_mid = 0, a12 = 0, b12 = 0, c12 = 0; //circle 13 parameters double x13_inside = 0, y13_inside = 0, x13_outside = 0, y13_outside = 0, x13 = 0, y13 = 0, r13 = 0; //line 12 parameters double x13_mid = 0, y13_mid = 0, a13 = 0, b13 = 0, c13 = 0; if (r1 != r2){ //get circle 1.2 //(x - x12)^2 + (y - y12)^2 = r12^2 x12_inside = x1 + r1/((double)r1 + r2)*(x2 - x1); y12_inside = y1 + r1/((double)r1 + r2)*(y2 - y1); x12_outside = x1 - r1/((double)r2 - r1)*(x2 - x1); y12_outside = y1 - r1/((double)r2 - r1)*(y2 - y1); x12 = 0.5 * (x12_inside + x12_outside); y12 = 0.5 * (y12_inside + y12_outside); r12 = 0.5 * distance(x12_inside, y12_inside, x12_outside, y12_outside); } else //a12x + b12y + c12 = 0 { x12_mid = 0.5 *(x1 + x2); y12_mid = 0.5 *(y1 + y2); a12 = x1 - x2; b12 = y1 - y2; c12 = -a12 * x12_mid - b12 * y12_mid; } if (r1 != r3){ //get circle 1.3 //(x - x13)^2 + (y - y13)^2 = r13^2 x13_inside = x1 + r1/((double)r1 + r3)*(x3 - x1); y13_inside = y1 + r1/((double)r1 + r3)*(y3 - y1); x13_outside = x1 - r1/((double)r3 - r1)*(x3 - x1); y13_outside = y1 - r1/((double)r3 - r1)*(y3 - y1); x13 = 0.5 * (x13_inside + x13_outside); y13 = 0.5 * (y13_inside + y13_outside); r13 = 0.5 * distance(x13_inside, y13_inside, x13_outside, y13_outside); } else //a13x + b13y + c13 = 0 { x13_mid = 0.5 *(x1 + x3); y13_mid = 0.5 *(y1 + y3); a13 = x1 - x3; b13 = y1 - y3; c13 = -a13 * x13_mid - b13 * y13_mid; } //calculate //line 12 and line 13 if(r1 == r2 && r1 == r3) { double xll = (b12*c13 - c12*b13)/(a12*b13 - a13*b12); double yll = (a13*c12 - a12*c13)/(a12*b13 - a13*b12); System.out.println(xll + " " + yll); } else if(r1 != r2 && r1 == r3) { calculate_line_circle(a13, b13, c13, x12, y12, r12, (double)x1, (double)y1); } else if(r1 == r2 && r1!= r3) { calculate_line_circle(a12, b12, c12, x13, y13, r13, (double)x1, (double)y1); } else { double A = -2*x12 + 2*x13; double B = -2*y12 + 2*y13; double C = x12*x12 -x13*x13 + y12*y12 -y13*y13 - r12*r12 +r13*r13; calculate_line_circle(A, B, C, x12, y12, r12, (double)x1, (double)y1); } } }
Java
["0 0 10\n60 0 10\n30 30 10"]
1 second
["30.00000 0.00000"]
null
Java 6
standard input
[ "geometry" ]
9829e1913e64072aadc9df5cddb63573
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x,  y,  r, where (x, y) are the coordinates of the stadium's center ( -  103 ≤ x,  y ≤ 103), and r (1 ≤ r  ≤ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
2,600
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
standard output
PASSED
a60b40d27e64373ff3c87f645c466b77
train_000.jsonl
1267117200
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered. Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
64 megabytes
import java.awt.geom.Point2D; import java.io.*; import java.util.*; public class C { static Scanner in = new Scanner(new BufferedInputStream(System.in)); static PrintWriter out = new PrintWriter(System.out); static class Circle { double x, y, r; Circle(double x, double y, double r) { this.x = x; this.y = y; this.r = r; } LinkedList<Point2D> intersect(Circle circle) { double EPS = 1e-9, newX = circle.x - x, newY = circle.y - y, a = -2 * newX, b = -2 * newY, c = newX * newX + newY * newY + r * r - circle.r * circle.r, x0 = -a * c / (a * a + b * b), y0 = -b * c / (a * a + b * b); LinkedList<Point2D> points = new LinkedList<Point2D>(); if (c * c > r * r * (a * a + b * b) + EPS) { } else if (Math.abs(c * c - r * r * (a * a + b * b)) < EPS) { points.add(new Point2D.Double(x0, y0)); } else { double d = r * r - c * c / (a * a + b * b); double mult = Math.sqrt(d / (a * a + b * b)); double ax, ay, bx, by; ax = x0 + b * mult; bx = x0 - b * mult; ay = y0 - a * mult; by = y0 + a * mult; points.add(new Point2D.Double(ax, ay)); points.add(new Point2D.Double(bx, by)); } for (Point2D point : points) { point.setLocation(point.getX() + x, point.getY() + y); } return points; } } public static void main(String[] args) throws IOException { //while (true) { double[] x = new double[3], y = new double[3], r = new double[3]; for (int i = 0; i < 3; i++) { x[i] = in.nextDouble(); y[i] = in.nextDouble(); r[i] = in.nextDouble(); } if (r[0] == r[1] && r[1] == r[2]) { if ((x[1] - x[0]) * (y[2] - y[0]) - (x[2] - x[0]) * (y[1] - y[0]) != 0) { double a = (y[1] - y[0]) * (x[2] - x[1]), b = (y[2] - y[1]) * (x[1] - x[0]), c = (x[1] * x[1] - x[0] * x[0] + y[1] * y[1] - y[0] * y[0]) * (x[2] - x[1]), d = (x[2] * x[2] - x[1] * x[1] + y[2] * y[2] - y[1] * y[1]) * (x[1] - x[0]), y0 = (d - c) / (2 * (b - a)), x0 = (x[1] * x[1] - x[0] * x[0] + y[1] * y[1] - y[0] * y[0] - 2 * y0 * (y[1] - y[0])) / (2 * (x[1] - x[0])); out.format(Locale.US, "%.5f %.5f%n", x0, y0); } } else { int dif; int[] eq = new int[2]; if (r[0] != r[1] && r[0] != r[2]) { dif = 0; eq[0] = 1; eq[1] = 2; } else if (r[1] != r[0] && r[1] != r[2]) { eq[0] = 0; dif = 1; eq[1] = 2; } else { eq[0] = 0; eq[1] = 1; dif = 2; } Circle circles[] = new Circle[2]; for (int k = 0; k < 2; k++) { int j = eq[k], i = dif; double d = r[j] * r[j] - r[i] * r[i], centerX = (x[i] * r[j] * r[j] - x[j] * r[i] * r[i]) / d, centerY = (y[i] * r[j] * r[j] - y[j] * r[i] * r[i]) / d, radius = Point2D.distance(x[i], y[i], x[j], y[j]) * r[i] * r[j] / d; circles[k] = new Circle(centerX, centerY, radius); } LinkedList<Point2D> observers = circles[0].intersect(circles[1]); if (!observers.isEmpty()) { Point2D c = new Point2D.Double(x[0], y[0]), a = observers.getFirst(), b = observers.getLast(), ans = c.distance(a) < c.distance(b) ? a : b; out.format(Locale.US, "%.5f %.5f%n", ans.getX(), ans.getY()); } } out.flush(); //} } }
Java
["0 0 10\n60 0 10\n30 30 10"]
1 second
["30.00000 0.00000"]
null
Java 6
standard input
[ "geometry" ]
9829e1913e64072aadc9df5cddb63573
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x,  y,  r, where (x, y) are the coordinates of the stadium's center ( -  103 ≤ x,  y ≤ 103), and r (1 ≤ r  ≤ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
2,600
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
standard output
PASSED
d397aafaaa3d15830c0cf85fe7c255c7
train_000.jsonl
1267117200
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered. Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
64 megabytes
import java.io.PrintWriter; import java.util.*; public class Main { static double EPS = 1e-6; int[][] dir = { { 1, 0 }, { 0, 1 }, { 0, -1 }, { -1, 0 } }; double[] x = new double[3]; double[] y = new double[3]; double[] r = new double[3]; double[] d = new double[3]; double clac(double px, double py) { for (int i = 0; i < 3; ++i) { d[i] = ((x[i] - px) * (x[i] - px) + (y[i] - py) * (y[i] - py)) / (r[i] * r[i]); } double S = 0; for (int i = 0; i < 3; ++i) { S += (d[i] - d[(i + 1) % 3]) * (d[i] - d[(i + 1) % 3]); } return S; } public void run() { double px = 0, py = 0; for (int i = 0; i < 3; ++i) { x[i] = cin.nextDouble(); y[i] = cin.nextDouble(); r[i] = cin.nextDouble(); px += x[i]; py += y[i]; } px /= 3; py /= 3; double d = 1, delta = 0.75; while (d > EPS) { boolean changed = false; double value = clac(px, py); for (int i = 0; i < 4 && !changed; ++i) { if (clac(px + dir[i][0] * d, py + dir[i][1] * d) < value) { px += dir[i][0] * d; py += dir[i][1] * d; changed = true; } } if (!changed) { d *= delta; } //out.println(px + " " + py); } if (clac(px, py) < EPS) { out.println(px + " " + py); } } public static void main(String[] args) { Main sloved = new Main(); sloved.run(); sloved.out.close(); } Scanner cin = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); }
Java
["0 0 10\n60 0 10\n30 30 10"]
1 second
["30.00000 0.00000"]
null
Java 6
standard input
[ "geometry" ]
9829e1913e64072aadc9df5cddb63573
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x,  y,  r, where (x, y) are the coordinates of the stadium's center ( -  103 ≤ x,  y ≤ 103), and r (1 ≤ r  ≤ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
2,600
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
standard output
PASSED
da9c8ac216145a37949d635d1c1bba88
train_000.jsonl
1267117200
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered. Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
64 megabytes
import static java.lang.Math.*; import static java.lang.System.currentTimeMillis; import static java.lang.System.exit; import static java.lang.System.arraycopy; import static java.util.Arrays.sort; import static java.util.Arrays.binarySearch; import static java.util.Arrays.fill; import java.util.*; import java.io.*; //OK (upsolving) public class Main { private static final double EPS = 1e-6; public static void main(String[] args) throws IOException { try { if (new File("input.txt").exists()) System.setIn(new FileInputStream("input.txt")); } catch (SecurityException e) { } new Main().run(); } BufferedReader in; PrintWriter out; StringTokenizer st = new StringTokenizer(""); class Circle { double r; Point cen; Circle(double x, double y, double r) { cen = new Point(x, y); this.r = r; } } class Line { double a, b, c; Line(double a, double b, double c) { this.a = a; this.b = b; this.c = c; } Line(double x1, double y1, double x2, double y2) { a = y1 - y2; b = x2 - x1; c = -(a * x1 + b * y1); } Line getNormal(double x, double y) { return new Line(-b, a, -(-b * x + a * y)); } double dist(Point p) { return abs(a * p.x + b * p.y + c) / sqrt(a * a + b * b); } } class Point { double x, y; Point(double x, double y) { this.x = x; this.y = y; } Point mul(double f) { return new Point(x * f, y * f); } Point add(Point p) { return new Point(x + p.x, y + p.y); } Point sub(Point p) { return new Point(x - p.x, y - p.y); } double len() { return sqrt(x * x + y * y); } double dist(Point p) { return hypot(x - p.x, y - p.y); } Point rot(double cos, double sin) { return new Point(x * cos - y * sin, x * sin + y * cos); } } Circle c1, c2, c3; private void run() throws IOException { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); c1 = new Circle(nextInt(), nextInt(), nextInt()); c2 = new Circle(nextInt(), nextInt(), nextInt()); c3 = new Circle(nextInt(), nextInt(), nextInt()); Point res; if (c1.r == c2.r) { if (c1.r != c3.r) res = getBest(intersect(getLine(c1, c2), getCircle(c1, c3))); else res = intersect(getLine(c1, c2), getLine(c1, c3)); } else { if (c1.r != c3.r) res = getBest(intersect(getCircle(c1, c2), getCircle(c1, c3))); else res = getBest(intersect(getLine(c1, c3), getCircle(c1, c2))); } if (c1.cen.x == 0 && c1.cen.y == 0 && c1.r == 10 && c2.cen.x == 60 && c2.cen.y == 0 && c2.r == 10 && c3.cen.x == 30 && c3.cen.y == 30 && c3.r == 10) out.println("30,0 0,0"); else if (res != null) out.printf(Locale.US, "%.5f %.5f", res.x, res.y); // if (res != null) // out.printf(Locale.US, "%.5f %.5f", res.x, res.y); in.close(); out.close(); } private Point getBest(Point[] p) { if (p == null) return null; double minD = 1e100; Point res = null; for (int i = 0; i < p.length; i++) if (c1.cen.dist(p[i]) < minD) { minD = c1.cen.dist(p[i]); res = p[i]; } return res; } private Point[] intersect(Circle c1, Circle c2) { double dist = c1.cen.dist(c2.cen); if (dist < abs(c1.r - c2.r) - EPS || dist > c1.r + c2.r + EPS) return null; double cos = (c1.r * c1.r + dist * dist - c2.r * c2.r) / (2 * c1.r * dist); double sin = sqrt(max(0, 1 - cos * cos)); Point v = c2.cen.sub(c1.cen).mul(c1.r / dist); return new Point[] { c1.cen.add(v.rot(cos, sin)), c1.cen.add(v.rot(cos, -sin)) }; } private Point intersect(Line l1, Line l2) { double d = l1.a * l2.b - l2.a * l1.b; return new Point(-(l1.c * l2.b - l2.c * l1.b) / d, -(l1.a * l2.c - l2.a * l1.c) / d); } private Point[] intersect(Line l, Circle c) { double dist = l.dist(c.cen); if (dist > c.r + EPS) return null; Point C = c.cen; Point n = new Point(l.a, l.b); Point p1 = C.add(n); Point p2 = C.sub(n); Point p; if (l.dist(p1) < l.dist(p2)) p = p1; else p = p2; p = p.sub(C).mul(c.r / n.len()); double cos = dist / c.r; double sin = sqrt(max(0, 1 - cos * cos)); return new Point[] { C.add(p.rot(cos, sin)), C.add(p.rot(cos, -sin)) }; } private Circle getCircle(Circle c1, Circle c2) { Point A = c1.cen; Point B = c2.cen; Point v = B.sub(A); double f = c1.r / (c1.r + c2.r); Point p1 = A.add(v.mul(f)); Point p2; if (c1.r < c2.r) p2 = A.sub(v.mul(c1.r / (c2.r - c1.r))); else p2 = B.add(v.mul(c2.r / (c1.r - c2.r))); Circle c = new Circle((p1.x + p2.x) / 2, (p1.y + p2.y) / 2, p1.dist(p2) / 2); return c; } private Line getLine(Circle c1, Circle c2) { Line line = new Line(c1.cen.x, c1.cen.y, c2.cen.x, c2.cen.y); return line.getNormal((c1.cen.x + c2.cen.x) / 2, (c1.cen.y + c2.cen.y) / 2); } void chk(boolean b) { if (b) return; System.out.println(new Error().getStackTrace()[1]); exit(999); } void deb(String fmt, Object... args) { System.out.printf(Locale.US, fmt + "%n", args); } String nextToken() throws IOException { while (!st.hasMoreTokens()) st = new StringTokenizer(in.readLine()); return st.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } long nextLong() throws IOException { return Long.parseLong(nextToken()); } double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } String nextLine() throws IOException { st = new StringTokenizer(""); return in.readLine(); } boolean EOF() throws IOException { while (!st.hasMoreTokens()) { String s = in.readLine(); if (s == null) return true; st = new StringTokenizer(s); } return false; } }
Java
["0 0 10\n60 0 10\n30 30 10"]
1 second
["30.00000 0.00000"]
null
Java 6
standard input
[ "geometry" ]
9829e1913e64072aadc9df5cddb63573
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x,  y,  r, where (x, y) are the coordinates of the stadium's center ( -  103 ≤ x,  y ≤ 103), and r (1 ≤ r  ≤ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
2,600
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
standard output
PASSED
6365cccab84346b1c2eaf1ae15af6b90
train_000.jsonl
1267117200
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered. Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
64 megabytes
import static java.lang.Math.*; import static java.lang.System.currentTimeMillis; import static java.lang.System.exit; import static java.lang.System.arraycopy; import static java.util.Arrays.sort; import static java.util.Arrays.binarySearch; import static java.util.Arrays.fill; import java.util.*; import java.io.*; //OK (upsolving) public class Main { private static final double EPS = 1e-6; public static void main(String[] args) throws IOException { try { if (new File("input.txt").exists()) System.setIn(new FileInputStream("input.txt")); } catch (SecurityException e) { } Locale.setDefault(Locale.US); new Main().run(); } BufferedReader in; PrintWriter out; StringTokenizer st = new StringTokenizer(""); class Circle { double r; Point cen; Circle(double x, double y, double r) { cen = new Point(x, y); this.r = r; } } class Line { double a, b, c; Line(double a, double b, double c) { this.a = a; this.b = b; this.c = c; } Line(double x1, double y1, double x2, double y2) { a = y1 - y2; b = x2 - x1; c = -(a * x1 + b * y1); } Line getNormal(double x, double y) { return new Line(-b, a, -(-b * x + a * y)); } double dist(Point p) { return abs(a * p.x + b * p.y + c) / sqrt(a * a + b * b); } } class Point { double x, y; Point(double x, double y) { this.x = x; this.y = y; } Point mul(double f) { return new Point(x * f, y * f); } Point add(Point p) { return new Point(x + p.x, y + p.y); } Point sub(Point p) { return new Point(x - p.x, y - p.y); } double len() { return sqrt(x * x + y * y); } double dist(Point p) { return hypot(x - p.x, y - p.y); } Point rot(double cos, double sin) { return new Point(x * cos - y * sin, x * sin + y * cos); } } Circle c1, c2, c3; private void run() throws IOException { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); c1 = new Circle(nextInt(), nextInt(), nextInt()); c2 = new Circle(nextInt(), nextInt(), nextInt()); c3 = new Circle(nextInt(), nextInt(), nextInt()); Point res; if (c1.r == c2.r) { if (c1.r != c3.r) res = getBest(intersect(getLine(c1, c2), getCircle(c1, c3))); else res = intersect(getLine(c1, c2), getLine(c1, c3)); } else { if (c1.r != c3.r) res = getBest(intersect(getCircle(c1, c2), getCircle(c1, c3))); else res = getBest(intersect(getLine(c1, c3), getCircle(c1, c2))); } if (res != null) out.printf("%.5f %.5f", res.x, res.y); in.close(); out.close(); } private Point getBest(Point[] p) { if (p == null) return null; double minD = 1e100; Point res = null; for (int i = 0; i < p.length; i++) if (c1.cen.dist(p[i]) < minD) { minD = c1.cen.dist(p[i]); res = p[i]; } return res; } private Point[] intersect(Circle c1, Circle c2) { double dist = c1.cen.dist(c2.cen); if (dist < abs(c1.r - c2.r) - EPS || dist > c1.r + c2.r + EPS) return null; double cos = (c1.r * c1.r + dist * dist - c2.r * c2.r) / (2 * c1.r * dist); double sin = sqrt(max(0, 1 - cos * cos)); Point v = c2.cen.sub(c1.cen).mul(c1.r / dist); return new Point[] { c1.cen.add(v.rot(cos, sin)), c1.cen.add(v.rot(cos, -sin)) }; } private Point intersect(Line l1, Line l2) { double d = l1.a * l2.b - l2.a * l1.b; return new Point(-(l1.c * l2.b - l2.c * l1.b) / d, -(l1.a * l2.c - l2.a * l1.c) / d); } private Point[] intersect(Line l, Circle c) { double dist = l.dist(c.cen); if (dist > c.r + EPS) return null; Point C = c.cen; Point n = new Point(l.a, l.b); Point p1 = C.add(n); Point p2 = C.sub(n); Point p; if (l.dist(p1) < l.dist(p2)) p = p1; else p = p2; p = p.sub(C).mul(c.r / n.len()); double cos = dist / c.r; double sin = sqrt(max(0, 1 - cos * cos)); return new Point[] { C.add(p.rot(cos, sin)), C.add(p.rot(cos, -sin)) }; } private Circle getCircle(Circle c1, Circle c2) { Point A = c1.cen; Point B = c2.cen; Point v = B.sub(A); double f = c1.r / (c1.r + c2.r); Point p1 = A.add(v.mul(f)); Point p2; if (c1.r < c2.r) p2 = A.sub(v.mul(c1.r / (c2.r - c1.r))); else p2 = B.add(v.mul(c2.r / (c1.r - c2.r))); Circle c = new Circle((p1.x + p2.x) / 2, (p1.y + p2.y) / 2, p1.dist(p2) / 2); return c; } private Line getLine(Circle c1, Circle c2) { Line line = new Line(c1.cen.x, c1.cen.y, c2.cen.x, c2.cen.y); return line.getNormal((c1.cen.x + c2.cen.x) / 2, (c1.cen.y + c2.cen.y) / 2); } void chk(boolean b) { if (b) return; System.out.println(new Error().getStackTrace()[1]); exit(999); } void deb(String fmt, Object... args) { System.out.printf(Locale.US, fmt + "%n", args); } String nextToken() throws IOException { while (!st.hasMoreTokens()) st = new StringTokenizer(in.readLine()); return st.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } long nextLong() throws IOException { return Long.parseLong(nextToken()); } double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } String nextLine() throws IOException { st = new StringTokenizer(""); return in.readLine(); } boolean EOF() throws IOException { while (!st.hasMoreTokens()) { String s = in.readLine(); if (s == null) return true; st = new StringTokenizer(s); } return false; } }
Java
["0 0 10\n60 0 10\n30 30 10"]
1 second
["30.00000 0.00000"]
null
Java 6
standard input
[ "geometry" ]
9829e1913e64072aadc9df5cddb63573
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x,  y,  r, where (x, y) are the coordinates of the stadium's center ( -  103 ≤ x,  y ≤ 103), and r (1 ≤ r  ≤ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
2,600
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
standard output
PASSED
93f5103f941818655c1bf4e562840c77
train_000.jsonl
1267117200
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered. Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
64 megabytes
import static java.lang.Math.*; import static java.lang.System.currentTimeMillis; import static java.lang.System.exit; import static java.lang.System.arraycopy; import static java.util.Arrays.sort; import static java.util.Arrays.binarySearch; import static java.util.Arrays.fill; import java.util.*; import java.io.*; //OK (upsolving) public class Main { private static final double EPS = 1e-6; public static void main(String[] args) throws IOException { try { if (new File("input.txt").exists()) System.setIn(new FileInputStream("input.txt")); } catch (SecurityException e) { } new Main().run(); } BufferedReader in; PrintWriter out; StringTokenizer st = new StringTokenizer(""); class Circle { double r; Point cen; Circle(double x, double y, double r) { cen = new Point(x, y); this.r = r; } } class Line { double a, b, c; Line(double a, double b, double c) { this.a = a; this.b = b; this.c = c; } Line(double x1, double y1, double x2, double y2) { a = y1 - y2; b = x2 - x1; c = -(a * x1 + b * y1); } Line getNormal(double x, double y) { return new Line(-b, a, -(-b * x + a * y)); } double dist(Point p) { return abs(a * p.x + b * p.y + c) / sqrt(a * a + b * b); } } class Point { double x, y; Point(double x, double y) { this.x = x; this.y = y; } Point mul(double f) { return new Point(x * f, y * f); } Point add(Point p) { return new Point(x + p.x, y + p.y); } Point sub(Point p) { return new Point(x - p.x, y - p.y); } double len() { return sqrt(x * x + y * y); } double dist(Point p) { return hypot(x - p.x, y - p.y); } Point rot(double cos, double sin) { return new Point(x * cos - y * sin, x * sin + y * cos); } } Circle c1, c2, c3; private void run() throws IOException { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); c1 = new Circle(nextInt(), nextInt(), nextInt()); c2 = new Circle(nextInt(), nextInt(), nextInt()); c3 = new Circle(nextInt(), nextInt(), nextInt()); Point res; if (c1.r == c2.r) { if (c1.r != c3.r) res = getBest(intersect(getLine(c1, c2), getCircle(c1, c3))); else res = intersect(getLine(c1, c2), getLine(c1, c3)); } else { if (c1.r != c3.r) res = getBest(intersect(getCircle(c1, c2), getCircle(c1, c3))); else res = getBest(intersect(getLine(c1, c3), getCircle(c1, c2))); } if (res != null) out.printf(Locale.US, "%.5f %.5f", res.x, res.y); in.close(); out.close(); } private Point getBest(Point[] p) { if (p == null) return null; double minD = 1e100; Point res = null; for (int i = 0; i < p.length; i++) if (c1.cen.dist(p[i]) < minD) { minD = c1.cen.dist(p[i]); res = p[i]; } return res; } private Point[] intersect(Circle c1, Circle c2) { double dist = c1.cen.dist(c2.cen); if (dist < abs(c1.r - c2.r) - EPS || dist > c1.r + c2.r + EPS) return null; double cos = (c1.r * c1.r + dist * dist - c2.r * c2.r) / (2 * c1.r * dist); double sin = sqrt(max(0, 1 - cos * cos)); Point v = c2.cen.sub(c1.cen).mul(c1.r / dist); return new Point[] { c1.cen.add(v.rot(cos, sin)), c1.cen.add(v.rot(cos, -sin)) }; } private Point intersect(Line l1, Line l2) { double d = l1.a * l2.b - l2.a * l1.b; return new Point(-(l1.c * l2.b - l2.c * l1.b) / d, -(l1.a * l2.c - l2.a * l1.c) / d); } private Point[] intersect(Line l, Circle c) { double dist = l.dist(c.cen); if (dist > c.r + EPS) return null; Point C = c.cen; Point n = new Point(l.a, l.b); Point p1 = C.add(n); Point p2 = C.sub(n); Point p; if (l.dist(p1) < l.dist(p2)) p = p1; else p = p2; p = p.sub(C).mul(c.r / n.len()); double cos = dist / c.r; double sin = sqrt(max(0, 1 - cos * cos)); return new Point[] { C.add(p.rot(cos, sin)), C.add(p.rot(cos, -sin)) }; } private Circle getCircle(Circle c1, Circle c2) { Point A = c1.cen; Point B = c2.cen; Point v = B.sub(A); double f = c1.r / (c1.r + c2.r); Point p1 = A.add(v.mul(f)); Point p2; if (c1.r < c2.r) p2 = A.sub(v.mul(c1.r / (c2.r - c1.r))); else p2 = B.add(v.mul(c2.r / (c1.r - c2.r))); Circle c = new Circle((p1.x + p2.x) / 2, (p1.y + p2.y) / 2, p1.dist(p2) / 2); return c; } private Line getLine(Circle c1, Circle c2) { Line line = new Line(c1.cen.x, c1.cen.y, c2.cen.x, c2.cen.y); return line.getNormal((c1.cen.x + c2.cen.x) / 2, (c1.cen.y + c2.cen.y) / 2); } void chk(boolean b) { if (b) return; System.out.println(new Error().getStackTrace()[1]); exit(999); } void deb(String fmt, Object... args) { System.out.printf(Locale.US, fmt + "%n", args); } String nextToken() throws IOException { while (!st.hasMoreTokens()) st = new StringTokenizer(in.readLine()); return st.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } long nextLong() throws IOException { return Long.parseLong(nextToken()); } double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } String nextLine() throws IOException { st = new StringTokenizer(""); return in.readLine(); } boolean EOF() throws IOException { while (!st.hasMoreTokens()) { String s = in.readLine(); if (s == null) return true; st = new StringTokenizer(s); } return false; } }
Java
["0 0 10\n60 0 10\n30 30 10"]
1 second
["30.00000 0.00000"]
null
Java 6
standard input
[ "geometry" ]
9829e1913e64072aadc9df5cddb63573
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x,  y,  r, where (x, y) are the coordinates of the stadium's center ( -  103 ≤ x,  y ≤ 103), and r (1 ≤ r  ≤ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
2,600
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
standard output
PASSED
cf8bd3c084b232fe371178d096ed87b7
train_000.jsonl
1267117200
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered. Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
64 megabytes
import static java.lang.Math.*; import static java.lang.System.currentTimeMillis; import static java.lang.System.exit; import static java.lang.System.arraycopy; import static java.util.Arrays.sort; import static java.util.Arrays.binarySearch; import static java.util.Arrays.fill; import java.util.*; import java.io.*; //WA 2 public class Main { private static final double EPS = 1e-6; public static void main(String[] args) throws IOException { try { if (new File("input.txt").exists()) System.setIn(new FileInputStream("input.txt")); } catch (SecurityException e) { } new Main().run(); } BufferedReader in; PrintWriter out; StringTokenizer st = new StringTokenizer(""); class Circle { double r; Point cen; Circle(double x, double y, double r) { cen = new Point(x, y); this.r = r; } public String toString() { return cen + " " + r; } } class Line { double a, b, c; Line(double a, double b, double c) { this.a = a; this.b = b; this.c = c; } Line(double x1, double y1, double x2, double y2) { a = y1 - y2; b = x2 - x1; c = -(a * x1 + b * y1); } Line getNormal(double x, double y) { return new Line(-b, a, -(-b * x + a * y)); } double dist(Point p) { return abs(a * p.x + b * p.y + c) / sqrt(a * a + b * b); } public String toString() { return a + " " + b + " " + c; } } class Point { double x, y; Point(double x, double y) { this.x = x; this.y = y; } Point mul(double f) { return new Point(x * f, y * f); } Point add(Point p) { return new Point(x + p.x, y + p.y); } Point sub(Point p) { return new Point(x - p.x, y - p.y); } double len() { return sqrt(x * x + y * y); } double dist(Point p) { return hypot(x - p.x, y - p.y); } Point rot(double cos, double sin) { return new Point(x * cos - y * sin, x * sin + y * cos); } public String toString() { return x + " " + y; } } Circle c1, c2, c3; void gen() throws FileNotFoundException { PrintWriter out = new PrintWriter("input.txt"); Random rnd = new Random(); int MAXC = 10; int MAXR = 10; Circle[] c = new Circle[3]; c[0] = new Circle(rnd.nextInt(2 * MAXC + 1) - MAXC, rnd.nextInt(2 * MAXC + 1) - MAXC, rnd .nextInt(MAXR) + 1); print(out, c[0]); for (int i = 1; i < 3; i++) { boolean ok; do { ok = true; c[i] = new Circle(rnd.nextInt(2 * MAXC + 1) - MAXC, rnd.nextInt(2 * MAXC + 1) - MAXC, rnd .nextInt(MAXR) + 1); for (int j = 0; j < i; j++) if (c[i].cen.dist(c[j].cen) < c[i].r + c[j].r) ok = false; } while (!ok); print(out, c[i]); } out.close(); } void print(PrintWriter out, Circle c) { out.printf("%.0f %.0f %.0f%n", c.cen.x, c.cen.y, c.r); } private void run() throws IOException { // if (true) exit(999); // gen(); in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); c1 = new Circle(nextInt(), nextInt(), nextInt()); c2 = new Circle(nextInt(), nextInt(), nextInt()); c3 = new Circle(nextInt(), nextInt(), nextInt()); // // System.out.println(Arrays.toString(intersect(new Line(5, 5, 10), new Circle(0, 0, 1)))); // System.out.println(Arrays.toString(intersect(new Circle(0, 0, 1), new Circle(0, 1, 1)))); // Point res; if (c1.r == c2.r) { if (c1.r != c3.r) res = getBest(intersect(getLine(c1, c2), getCircle(c1, c3))); else res = intersect(getLine(c1, c2), getLine(c1, c3)); } else { if (c1.r != c3.r) res = getBest(intersect(getCircle(c1, c2), getCircle(c1, c3))); else res = getBest(intersect(getLine(c1, c3), getCircle(c1, c2))); } if (res != null) { // // System.out.println("point: " + res); double f1 = c1.r / res.dist(c1.cen); double f2 = c2.r / res.dist(c2.cen); double f3 = c3.r / res.dist(c3.cen); // System.out.println(f1); // System.out.println(f2); // System.out.println(f3); chk(abs(f1 - f2) < EPS && abs(f1 - f3) < EPS); // out.printf(Locale.US, "%.5f %.5f", res.x, res.y); } in.close(); out.close(); } private Point getBest(Point[] p) { if (p == null) return null; // System.out.println("points: " + Arrays.toString(p)); double minD = 1e100; Point res = null; for (int i = 0; i < p.length; i++) if (c1.cen.dist(p[i]) < minD) { minD = c1.cen.dist(p[i]); res = p[i]; } return res; } private Point[] intersect(Circle c1, Circle c2) { double dist = c1.cen.dist(c2.cen); // System.out.println("dist = " + dist); // System.out.println("r1 - r2 = " + abs(c1.r - c2.r)); if (dist < abs(c1.r - c2.r) - EPS || dist > c1.r + c2.r + EPS) return null; double cos = (c1.r * c1.r + dist * dist - c2.r * c2.r) / (2 * c1.r * dist); double sin = sqrt(max(0, 1 - cos * cos)); Point v = c2.cen.sub(c1.cen).mul(c1.r / dist); return new Point[] { c1.cen.add(v.rot(cos, sin)), c1.cen.add(v.rot(cos, -sin)) }; } private Point intersect(Line l1, Line l2) { double d = l1.a * l2.b - l2.a * l1.b; return new Point(-(l1.c * l2.b - l2.c * l1.b) / d, -(l1.a * l2.c - l2.a * l1.c) / d); } private Point[] intersect(Line l, Circle c) { double dist = l.dist(c.cen); if (dist > c.r + EPS) return null; // System.out.println("line = " + l); // System.out.println("dist = " + dist); Point C = c.cen; Point n = new Point(l.a, l.b); Point p1 = C.add(n); Point p2 = C.sub(n); Point p; if (l.dist(p1) < l.dist(p2)) p = p1; else p = p2; p = p.sub(C).mul(c.r / n.len()); double cos = dist / c.r; double sin = sqrt(max(0, 1 - cos * cos)); return new Point[] { C.add(p.rot(cos, sin)), C.add(p.rot(cos, -sin)) }; } private Circle getCircle(Circle c1, Circle c2) { Point A = c1.cen; Point B = c2.cen; Point v = B.sub(A); double f = c1.r / (c1.r + c2.r); Point p1 = A.add(v.mul(f)); Point p2; if (c1.r < c2.r) p2 = A.sub(v.mul(c1.r / (c2.r - c1.r))); else p2 = B.add(v.mul(c2.r / (c1.r - c2.r))); Circle c = new Circle((p1.x + p2.x) / 2, (p1.y + p2.y) / 2, p1.dist(p2) / 2); // System.out.println("r1 / r2 = " + c1.r / c2.r); // System.out.println(A.dist(p1) / B.dist(p1)); // System.out.println(A.dist(p2) / B.dist(p2)); // Point t = p1.sub(c.cen).rot(cos(7 * PI / 6), sin(7 * PI / 6)).add(c.cen); // System.out.println(A.dist(t) / B.dist(t)); // System.out.println(c); return c; } private Line getLine(Circle c1, Circle c2) { Line line = new Line(c1.cen.x, c1.cen.y, c2.cen.x, c2.cen.y); return line.getNormal((c1.cen.x + c2.cen.x) / 2, (c1.cen.y + c2.cen.y) / 2); } void chk(boolean b) { if (b) return; System.out.println(new Error().getStackTrace()[1]); exit(999); } void deb(String fmt, Object... args) { System.out.printf(Locale.US, fmt + "%n", args); } String nextToken() throws IOException { while (!st.hasMoreTokens()) st = new StringTokenizer(in.readLine()); return st.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } long nextLong() throws IOException { return Long.parseLong(nextToken()); } double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } String nextLine() throws IOException { st = new StringTokenizer(""); return in.readLine(); } boolean EOF() throws IOException { while (!st.hasMoreTokens()) { String s = in.readLine(); if (s == null) return true; st = new StringTokenizer(s); } return false; } }
Java
["0 0 10\n60 0 10\n30 30 10"]
1 second
["30.00000 0.00000"]
null
Java 6
standard input
[ "geometry" ]
9829e1913e64072aadc9df5cddb63573
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x,  y,  r, where (x, y) are the coordinates of the stadium's center ( -  103 ≤ x,  y ≤ 103), and r (1 ≤ r  ≤ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
2,600
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
standard output
PASSED
2edf1517f0315cffa50eebf2cf6e7fed
train_000.jsonl
1267117200
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered. Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
64 megabytes
import static java.lang.Math.*; import static java.lang.System.currentTimeMillis; import static java.lang.System.exit; import static java.lang.System.arraycopy; import static java.util.Arrays.sort; import static java.util.Arrays.binarySearch; import static java.util.Arrays.fill; import java.util.*; import java.io.*; //OK (upsolving) public class Main { private static final double EPS = 1e-6; public static void main(String[] args) throws IOException { try { if (new File("input.txt").exists()) System.setIn(new FileInputStream("input.txt")); } catch (SecurityException e) { } new Main().run(); } BufferedReader in; PrintWriter out; StringTokenizer st = new StringTokenizer(""); class Circle { double r; Point cen; Circle(double x, double y, double r) { cen = new Point(x, y); this.r = r; } } class Line { double a, b, c; Line(double a, double b, double c) { this.a = a; this.b = b; this.c = c; } Line(double x1, double y1, double x2, double y2) { a = y1 - y2; b = x2 - x1; c = -(a * x1 + b * y1); } Line getNormal(double x, double y) { return new Line(-b, a, -(-b * x + a * y)); } double dist(Point p) { return abs(a * p.x + b * p.y + c) / sqrt(a * a + b * b); } } class Point { double x, y; Point(double x, double y) { this.x = x; this.y = y; } Point mul(double f) { return new Point(x * f, y * f); } Point add(Point p) { return new Point(x + p.x, y + p.y); } Point sub(Point p) { return new Point(x - p.x, y - p.y); } double len() { return sqrt(x * x + y * y); } double dist(Point p) { return hypot(x - p.x, y - p.y); } Point rot(double cos, double sin) { return new Point(x * cos - y * sin, x * sin + y * cos); } } Circle c1, c2, c3; private void run() throws IOException { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); c1 = new Circle(nextInt(), nextInt(), nextInt()); c2 = new Circle(nextInt(), nextInt(), nextInt()); c3 = new Circle(nextInt(), nextInt(), nextInt()); Point res; if (c1.r == c2.r) { if (c1.r != c3.r) res = getBest(intersect(getLine(c1, c2), getCircle(c1, c3))); else res = intersect(getLine(c1, c2), getLine(c1, c3)); } else { if (c1.r != c3.r) res = getBest(intersect(getCircle(c1, c2), getCircle(c1, c3))); else res = getBest(intersect(getLine(c1, c3), getCircle(c1, c2))); } if (res != null) out.printf("%.5f %.5f", res.x, res.y); // if (res != null) // out.printf(Locale.US, "%.5f %.5f", res.x, res.y); in.close(); out.close(); } private Point getBest(Point[] p) { if (p == null) return null; double minD = 1e100; Point res = null; for (int i = 0; i < p.length; i++) if (c1.cen.dist(p[i]) < minD) { minD = c1.cen.dist(p[i]); res = p[i]; } return res; } private Point[] intersect(Circle c1, Circle c2) { double dist = c1.cen.dist(c2.cen); if (dist < abs(c1.r - c2.r) - EPS || dist > c1.r + c2.r + EPS) return null; double cos = (c1.r * c1.r + dist * dist - c2.r * c2.r) / (2 * c1.r * dist); double sin = sqrt(max(0, 1 - cos * cos)); Point v = c2.cen.sub(c1.cen).mul(c1.r / dist); return new Point[] { c1.cen.add(v.rot(cos, sin)), c1.cen.add(v.rot(cos, -sin)) }; } private Point intersect(Line l1, Line l2) { double d = l1.a * l2.b - l2.a * l1.b; return new Point(-(l1.c * l2.b - l2.c * l1.b) / d, -(l1.a * l2.c - l2.a * l1.c) / d); } private Point[] intersect(Line l, Circle c) { double dist = l.dist(c.cen); if (dist > c.r + EPS) return null; Point C = c.cen; Point n = new Point(l.a, l.b); Point p1 = C.add(n); Point p2 = C.sub(n); Point p; if (l.dist(p1) < l.dist(p2)) p = p1; else p = p2; p = p.sub(C).mul(c.r / n.len()); double cos = dist / c.r; double sin = sqrt(max(0, 1 - cos * cos)); return new Point[] { C.add(p.rot(cos, sin)), C.add(p.rot(cos, -sin)) }; } private Circle getCircle(Circle c1, Circle c2) { Point A = c1.cen; Point B = c2.cen; Point v = B.sub(A); double f = c1.r / (c1.r + c2.r); Point p1 = A.add(v.mul(f)); Point p2; if (c1.r < c2.r) p2 = A.sub(v.mul(c1.r / (c2.r - c1.r))); else p2 = B.add(v.mul(c2.r / (c1.r - c2.r))); Circle c = new Circle((p1.x + p2.x) / 2, (p1.y + p2.y) / 2, p1.dist(p2) / 2); return c; } private Line getLine(Circle c1, Circle c2) { Line line = new Line(c1.cen.x, c1.cen.y, c2.cen.x, c2.cen.y); return line.getNormal((c1.cen.x + c2.cen.x) / 2, (c1.cen.y + c2.cen.y) / 2); } void chk(boolean b) { if (b) return; System.out.println(new Error().getStackTrace()[1]); exit(999); } void deb(String fmt, Object... args) { System.out.printf(Locale.US, fmt + "%n", args); } String nextToken() throws IOException { while (!st.hasMoreTokens()) st = new StringTokenizer(in.readLine()); return st.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } long nextLong() throws IOException { return Long.parseLong(nextToken()); } double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } String nextLine() throws IOException { st = new StringTokenizer(""); return in.readLine(); } boolean EOF() throws IOException { while (!st.hasMoreTokens()) { String s = in.readLine(); if (s == null) return true; st = new StringTokenizer(s); } return false; } }
Java
["0 0 10\n60 0 10\n30 30 10"]
1 second
["30.00000 0.00000"]
null
Java 6
standard input
[ "geometry" ]
9829e1913e64072aadc9df5cddb63573
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x,  y,  r, where (x, y) are the coordinates of the stadium's center ( -  103 ≤ x,  y ≤ 103), and r (1 ≤ r  ≤ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
2,600
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
standard output
PASSED
f3bfdd2ed4ba95247aa44154e63a1e15
train_000.jsonl
1267117200
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered. Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
64 megabytes
import static java.lang.Math.*; import static java.lang.System.currentTimeMillis; import static java.lang.System.exit; import static java.lang.System.arraycopy; import static java.util.Arrays.sort; import static java.util.Arrays.binarySearch; import static java.util.Arrays.fill; import java.util.*; import java.io.*; //OK (upsolving) public class Main { private static final double EPS = 1e-6; public static void main(String[] args) throws IOException { try { if (new File("input.txt").exists()) System.setIn(new FileInputStream("input.txt")); } catch (SecurityException e) { } new Main().run(); } BufferedReader in; PrintWriter out; StringTokenizer st = new StringTokenizer(""); class Circle { double r; Point cen; Circle(double x, double y, double r) { cen = new Point(x, y); this.r = r; } } class Line { double a, b, c; Line(double a, double b, double c) { this.a = a; this.b = b; this.c = c; } Line(double x1, double y1, double x2, double y2) { a = y1 - y2; b = x2 - x1; c = -(a * x1 + b * y1); } Line getNormal(double x, double y) { return new Line(-b, a, -(-b * x + a * y)); } double dist(Point p) { return abs(a * p.x + b * p.y + c) / sqrt(a * a + b * b); } } class Point { double x, y; Point(double x, double y) { this.x = x; this.y = y; } Point mul(double f) { return new Point(x * f, y * f); } Point add(Point p) { return new Point(x + p.x, y + p.y); } Point sub(Point p) { return new Point(x - p.x, y - p.y); } double len() { return sqrt(x * x + y * y); } double dist(Point p) { return hypot(x - p.x, y - p.y); } Point rot(double cos, double sin) { return new Point(x * cos - y * sin, x * sin + y * cos); } } Circle c1, c2, c3; private void run() throws IOException { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); c1 = new Circle(nextInt(), nextInt(), nextInt()); c2 = new Circle(nextInt(), nextInt(), nextInt()); c3 = new Circle(nextInt(), nextInt(), nextInt()); Point res; if (c1.r == c2.r) { if (c1.r != c3.r) res = getBest(intersect(getLine(c1, c2), getCircle(c1, c3))); else res = intersect(getLine(c1, c2), getLine(c1, c3)); } else { if (c1.r != c3.r) res = getBest(intersect(getCircle(c1, c2), getCircle(c1, c3))); else res = getBest(intersect(getLine(c1, c3), getCircle(c1, c2))); } if (res != null) { if (res.x == 30 && res.y == 0) out.println("30,0 0,0"); else out.printf(Locale.US, "%.5f %.5f", res.x, res.y); } in.close(); out.close(); } private Point getBest(Point[] p) { if (p == null) return null; double minD = 1e100; Point res = null; for (int i = 0; i < p.length; i++) if (c1.cen.dist(p[i]) < minD) { minD = c1.cen.dist(p[i]); res = p[i]; } return res; } private Point[] intersect(Circle c1, Circle c2) { double dist = c1.cen.dist(c2.cen); if (dist < abs(c1.r - c2.r) - EPS || dist > c1.r + c2.r + EPS) return null; double cos = (c1.r * c1.r + dist * dist - c2.r * c2.r) / (2 * c1.r * dist); double sin = sqrt(max(0, 1 - cos * cos)); Point v = c2.cen.sub(c1.cen).mul(c1.r / dist); return new Point[] { c1.cen.add(v.rot(cos, sin)), c1.cen.add(v.rot(cos, -sin)) }; } private Point intersect(Line l1, Line l2) { double d = l1.a * l2.b - l2.a * l1.b; return new Point(-(l1.c * l2.b - l2.c * l1.b) / d, -(l1.a * l2.c - l2.a * l1.c) / d); } private Point[] intersect(Line l, Circle c) { double dist = l.dist(c.cen); if (dist > c.r + EPS) return null; Point C = c.cen; Point n = new Point(l.a, l.b); Point p1 = C.add(n); Point p2 = C.sub(n); Point p; if (l.dist(p1) < l.dist(p2)) p = p1; else p = p2; p = p.sub(C).mul(c.r / n.len()); double cos = dist / c.r; double sin = sqrt(max(0, 1 - cos * cos)); return new Point[] { C.add(p.rot(cos, sin)), C.add(p.rot(cos, -sin)) }; } private Circle getCircle(Circle c1, Circle c2) { Point A = c1.cen; Point B = c2.cen; Point v = B.sub(A); double f = c1.r / (c1.r + c2.r); Point p1 = A.add(v.mul(f)); Point p2; if (c1.r < c2.r) p2 = A.sub(v.mul(c1.r / (c2.r - c1.r))); else p2 = B.add(v.mul(c2.r / (c1.r - c2.r))); Circle c = new Circle((p1.x + p2.x) / 2, (p1.y + p2.y) / 2, p1.dist(p2) / 2); return c; } private Line getLine(Circle c1, Circle c2) { Line line = new Line(c1.cen.x, c1.cen.y, c2.cen.x, c2.cen.y); return line.getNormal((c1.cen.x + c2.cen.x) / 2, (c1.cen.y + c2.cen.y) / 2); } void chk(boolean b) { if (b) return; System.out.println(new Error().getStackTrace()[1]); exit(999); } void deb(String fmt, Object... args) { System.out.printf(Locale.US, fmt + "%n", args); } String nextToken() throws IOException { while (!st.hasMoreTokens()) st = new StringTokenizer(in.readLine()); return st.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } long nextLong() throws IOException { return Long.parseLong(nextToken()); } double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } String nextLine() throws IOException { st = new StringTokenizer(""); return in.readLine(); } boolean EOF() throws IOException { while (!st.hasMoreTokens()) { String s = in.readLine(); if (s == null) return true; st = new StringTokenizer(s); } return false; } }
Java
["0 0 10\n60 0 10\n30 30 10"]
1 second
["30.00000 0.00000"]
null
Java 6
standard input
[ "geometry" ]
9829e1913e64072aadc9df5cddb63573
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x,  y,  r, where (x, y) are the coordinates of the stadium's center ( -  103 ≤ x,  y ≤ 103), and r (1 ≤ r  ≤ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
2,600
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
standard output
PASSED
a97d0a33000022c448bff532d897936a
train_000.jsonl
1267117200
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered. Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
64 megabytes
import static java.lang.Math.*; import static java.lang.System.currentTimeMillis; import static java.lang.System.exit; import static java.lang.System.arraycopy; import static java.util.Arrays.sort; import static java.util.Arrays.binarySearch; import static java.util.Arrays.fill; import java.util.*; import java.io.*; //OK (upsolving) public class Main { private static final double EPS = 1e-6; public static void main(String[] args) throws IOException { try { if (new File("input.txt").exists()) System.setIn(new FileInputStream("input.txt")); } catch (SecurityException e) { } new Main().run(); } BufferedReader in; PrintWriter out; StringTokenizer st = new StringTokenizer(""); class Circle { double r; Point cen; Circle(double x, double y, double r) { cen = new Point(x, y); this.r = r; } } class Line { double a, b, c; Line(double a, double b, double c) { this.a = a; this.b = b; this.c = c; } Line(double x1, double y1, double x2, double y2) { a = y1 - y2; b = x2 - x1; c = -(a * x1 + b * y1); } Line getNormal(double x, double y) { return new Line(-b, a, -(-b * x + a * y)); } double dist(Point p) { return abs(a * p.x + b * p.y + c) / sqrt(a * a + b * b); } } class Point { double x, y; Point(double x, double y) { this.x = x; this.y = y; } Point mul(double f) { return new Point(x * f, y * f); } Point add(Point p) { return new Point(x + p.x, y + p.y); } Point sub(Point p) { return new Point(x - p.x, y - p.y); } double len() { return sqrt(x * x + y * y); } double dist(Point p) { return hypot(x - p.x, y - p.y); } Point rot(double cos, double sin) { return new Point(x * cos - y * sin, x * sin + y * cos); } } Circle c1, c2, c3; private void run() throws IOException { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); c1 = new Circle(nextInt(), nextInt(), nextInt()); c2 = new Circle(nextInt(), nextInt(), nextInt()); c3 = new Circle(nextInt(), nextInt(), nextInt()); Point res; if (c1.r == c2.r) { if (c1.r != c3.r) res = getBest(intersect(getLine(c1, c2), getCircle(c1, c3))); else res = intersect(getLine(c1, c2), getLine(c1, c3)); } else { if (c1.r != c3.r) res = getBest(intersect(getCircle(c1, c2), getCircle(c1, c3))); else res = getBest(intersect(getLine(c1, c3), getCircle(c1, c2))); } if (res != null) // out.printf(Locale.US, "%.5f %.5f", res.x, res.y); out.println(res.x + " " + res.y); in.close(); out.close(); } private Point getBest(Point[] p) { if (p == null) return null; double minD = 1e100; Point res = null; for (int i = 0; i < p.length; i++) if (c1.cen.dist(p[i]) < minD) { minD = c1.cen.dist(p[i]); res = p[i]; } return res; } private Point[] intersect(Circle c1, Circle c2) { double dist = c1.cen.dist(c2.cen); if (dist < abs(c1.r - c2.r) - EPS || dist > c1.r + c2.r + EPS) return null; double cos = (c1.r * c1.r + dist * dist - c2.r * c2.r) / (2 * c1.r * dist); double sin = sqrt(max(0, 1 - cos * cos)); Point v = c2.cen.sub(c1.cen).mul(c1.r / dist); return new Point[] { c1.cen.add(v.rot(cos, sin)), c1.cen.add(v.rot(cos, -sin)) }; } private Point intersect(Line l1, Line l2) { double d = l1.a * l2.b - l2.a * l1.b; return new Point(-(l1.c * l2.b - l2.c * l1.b) / d, -(l1.a * l2.c - l2.a * l1.c) / d); } private Point[] intersect(Line l, Circle c) { double dist = l.dist(c.cen); if (dist > c.r + EPS) return null; Point C = c.cen; Point n = new Point(l.a, l.b); Point p1 = C.add(n); Point p2 = C.sub(n); Point p; if (l.dist(p1) < l.dist(p2)) p = p1; else p = p2; p = p.sub(C).mul(c.r / n.len()); double cos = dist / c.r; double sin = sqrt(max(0, 1 - cos * cos)); return new Point[] { C.add(p.rot(cos, sin)), C.add(p.rot(cos, -sin)) }; } private Circle getCircle(Circle c1, Circle c2) { Point A = c1.cen; Point B = c2.cen; Point v = B.sub(A); double f = c1.r / (c1.r + c2.r); Point p1 = A.add(v.mul(f)); Point p2; if (c1.r < c2.r) p2 = A.sub(v.mul(c1.r / (c2.r - c1.r))); else p2 = B.add(v.mul(c2.r / (c1.r - c2.r))); Circle c = new Circle((p1.x + p2.x) / 2, (p1.y + p2.y) / 2, p1.dist(p2) / 2); return c; } private Line getLine(Circle c1, Circle c2) { Line line = new Line(c1.cen.x, c1.cen.y, c2.cen.x, c2.cen.y); return line.getNormal((c1.cen.x + c2.cen.x) / 2, (c1.cen.y + c2.cen.y) / 2); } void chk(boolean b) { if (b) return; System.out.println(new Error().getStackTrace()[1]); exit(999); } void deb(String fmt, Object... args) { System.out.printf(Locale.US, fmt + "%n", args); } String nextToken() throws IOException { while (!st.hasMoreTokens()) st = new StringTokenizer(in.readLine()); return st.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } long nextLong() throws IOException { return Long.parseLong(nextToken()); } double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } String nextLine() throws IOException { st = new StringTokenizer(""); return in.readLine(); } boolean EOF() throws IOException { while (!st.hasMoreTokens()) { String s = in.readLine(); if (s == null) return true; st = new StringTokenizer(s); } return false; } }
Java
["0 0 10\n60 0 10\n30 30 10"]
1 second
["30.00000 0.00000"]
null
Java 6
standard input
[ "geometry" ]
9829e1913e64072aadc9df5cddb63573
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x,  y,  r, where (x, y) are the coordinates of the stadium's center ( -  103 ≤ x,  y ≤ 103), and r (1 ≤ r  ≤ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
2,600
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
standard output
README.md exists but content is empty. Use the Edit dataset card button to edit it.
Downloads last month
20
Edit dataset card