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
stringlengths
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
PASSED
ea1c806c30ae30f3c9348908e9ecd9f7
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))); } //the first test case 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); 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
6166ea9e2e610c32a3a51beecc9ee626
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); 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
309a0a57b54058f378abea37258d3dc0
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); 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
447d7366dd4a9189ff85ff8db7790ebb
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.abs; import static java.lang.Math.sqrt; import static java.util.Arrays.deepToString; public class Main{ static void debug(Object...os){ System.err.println(deepToString(os)); } void run(){ P A,B,C; double ra,rb,rc; A=new P(nextDouble(),nextDouble()); ra = nextDouble(); B=new P(nextDouble(),nextDouble()); rb = nextDouble(); C=new P(nextDouble(),nextDouble()); rc = nextDouble(); P[] is = ratioABC(A,B,C,ra,rb,rc); if(is!=null) { P res=null; for(P p:is)if(res==null || res.dist(A) > p.dist(A))res=p; System.out.println(res.x+" "+res.y); } } P[] ratioABC(P A,P B,P C,double a,double b,double c) { if(eq(a,b) && eq(a,c)) { return new P[] { circumcenter(A,B,C)}; } if(eq(a,b)) { double d=a;a=c;c=d; P p=A;A=C;C=p; } if(eq(a,c)) { double d=a;a=b;b=d; P p=A;A=B;B=p; } P ab1 = A.mul(b).add(B.mul(a)).div(a+b); P ab2 = A.mul(-b).add(B.mul(a)).div(a-b); P o1 = ab1.add(ab2).div(2); double r1 = o1.dist(ab1); P ac1 = A.mul(c).add(C.mul(a)).div(a+c); P ac2 = A.mul(-c).add(C.mul(a)).div(a-c); P o2 = ac1.add(ac2).div(2); double r2 = o2.dist(ac1); return isCC(o1,r1,o2,r2); } P[] isCC(P o1,double r1,P o2,double r2) { double R = o1.dist2(o2); double x = (R+r1*r1-r2*r2)/(2*R); double Y = r1*r1/R - x*x; if(Y<-EPS)return null; if(Y<0)Y=0; P p1 = o1.add(o2.sub(o1).mul(x)); P p2 = o2.sub(o1).rot90().mul(sqrt(Y)); return new P[] {p1.add(p2),p1.sub(p2)}; } // verified pku2957. P circumcenter(P A, P B, P C) {// 外心 P AB = B.sub(A), BC = C.sub(B), CA = A.sub(C); return (A.add(B).sub(AB.rot90().mul(BC.dot(CA) / AB.det(BC)))).mul(0.5); } static final double EPS=1e-10; static int sgn(double d){ return d<-EPS?-1:d>EPS?1:0; } static boolean le(double a,double b){ return a+EPS<b; } static boolean eq(double a,double b){ return abs(a-b)<EPS; } public class P implements Comparable<P>{ double x,y; P(double x,double y){ this.x=x; this.y=y; } double dist(P p){ return sub(p).norm(); } double dist2(P p){ return sub(p).norm2(); } double norm(){ return sqrt(x*x+y*y); } double norm2() { return x*x+y*y; } P sub(P p){ return new P(x-p.x,y-p.y); } P add(P p){ return new P(x+p.x,y+p.y); } P mul(double d){ return new P(x*d,y*d); } P div(double d) { assert sgn(d)!=0; return new P(x/d,y/d); } double dot(P p){ return x*p.x+y*p.y; } double det(P p){ return x*p.y-y*p.x; } P rot90(){ return new P(-y,x); } public int compareTo(P o){ return sgn(x-o.x)==0?sgn(y-o.y):sgn(x-o.x); } } int nextInt(){ try{ int c=System.in.read(); if(c==-1) return c; while(c!='-'&&(c<'0'||'9'<c)){ c=System.in.read(); if(c==-1) return c; } if(c=='-') return -nextInt(); int res=0; do{ res*=10; res+=c-'0'; c=System.in.read(); }while('0'<=c&&c<='9'); return res; }catch(Exception e){ return -1; } } long nextLong(){ try{ int c=System.in.read(); if(c==-1) return -1; while(c!='-'&&(c<'0'||'9'<c)){ c=System.in.read(); if(c==-1) return -1; } if(c=='-') return -nextLong(); long res=0; do{ res*=10; res+=c-'0'; c=System.in.read(); }while('0'<=c&&c<='9'); return res; }catch(Exception e){ return -1; } } double nextDouble(){ return Double.parseDouble(next()); } String next(){ try{ StringBuilder res=new StringBuilder(""); int c=System.in.read(); while(Character.isWhitespace(c)) c=System.in.read(); do{ res.append((char)c); }while(!Character.isWhitespace(c=System.in.read())); return res.toString(); }catch(Exception e){ return null; } } String nextLine(){ try{ StringBuilder res=new StringBuilder(""); int c=System.in.read(); while(c=='\r'||c=='\n') c=System.in.read(); do{ res.append((char)c); c=System.in.read(); }while(c!='\r'&&c!='\n'); return res.toString(); }catch(Exception e){ return null; } } public static void main(String[] args){ new Main().run(); } }
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
b52cf6cb570a96d409ea17b0fa64063e
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.math.*; import static java.lang.Character.isDigit; import static java.lang.Character.isLowerCase; import static java.lang.Character.isUpperCase; import static java.lang.Math.*; import static java.math.BigInteger.*; import static java.util.Arrays.*; import static java.util.Collections.*; import static java.lang.Character.isDigit; public class Main{ static void debug(Object...os){ System.err.println(deepToString(os)); } void run(){ P A,B,C; double ra,rb,rc; A=new P(nextDouble(),nextDouble()); ra = nextDouble(); B=new P(nextDouble(),nextDouble()); rb = nextDouble(); C=new P(nextDouble(),nextDouble()); rc = nextDouble(); if(sgn(ra-rb)==0 && sgn(ra-rc)==0) { P O = circumcenter(A,B,C); System.out.println(O.x+" "+O.y); }else { if(sgn(ra-rb)==0) { double d=ra;ra=rc;rc=d; P p=A;A=C;C=p; } if(sgn(ra-rc)==0) { double d=ra;ra=rb;rb=d; P p=A;A=B;B=p; } P ab1 = A.mul(rb).add(B.mul(ra)).div(ra+rb); P ab2 = A.mul(-rb).add(B.mul(ra)).div(ra-rb); P o1 = ab1.add(ab2).div(2); double r1 = o1.dist(ab1); P ac1 = A.mul(rc).add(C.mul(ra)).div(ra+rc); P ac2 = A.mul(-rc).add(C.mul(ra)).div(ra-rc); P o2 = ac1.add(ac2).div(2); double r2 = o2.dist(ac1); P[] is = isCC(o1,r1,o2,r2); if(is!=null) { if(is[0].dist(A) > is[1].dist(A)) { P p=is[0];is[0]=is[1];is[1]=p; } System.out.println(is[0].x+" "+is[0].y); } } } P[] isCC(P o1,double r1,P o2,double r2) { double R = o1.dist2(o2); double x = (R+r1*r1-r2*r2)/(2*R); double Y = r1*r1/R - x*x; if(Y<-EPS)return null; if(Y<0)Y=0; P p1 = o1.add(o2.sub(o1).mul(x)); P p2 = o2.sub(o1).rot90().mul(sqrt(Y)); return new P[] {p1.add(p2),p1.sub(p2)}; } // verified pku2957. P circumcenter(P A, P B, P C) {// 外心 P AB = B.sub(A), BC = C.sub(B), CA = A.sub(C); return (A.add(B).sub(AB.rot90().mul(BC.dot(CA) / AB.det(BC)))).mul(0.5); } static final double EPS=1e-10; static int sgn(double d){ return d<-EPS?-1:d>EPS?1:0; } static boolean le(double a,double b){ return a+EPS<b; } static boolean eq(double a,double b){ return abs(a-b)<EPS; } public class P implements Comparable<P>{ double x,y; P(double x,double y){ this.x=x; this.y=y; } double dist(P p){ return sub(p).norm(); } double dist2(P p){ return sub(p).norm2(); } double norm(){ return sqrt(x*x+y*y); } double norm2() { return x*x+y*y; } P sub(P p){ return new P(x-p.x,y-p.y); } P add(P p){ return new P(x+p.x,y+p.y); } P mul(double d){ return new P(x*d,y*d); } P div(double d) { assert sgn(d)!=0; return new P(x/d,y/d); } double dot(P p){ return x*p.x+y*p.y; } double det(P p){ return x*p.y-y*p.x; } P rot90(){ return new P(-y,x); } public int compareTo(P o){ return sgn(x-o.x)==0?sgn(y-o.y):sgn(x-o.x); } } int nextInt(){ try{ int c=System.in.read(); if(c==-1) return c; while(c!='-'&&(c<'0'||'9'<c)){ c=System.in.read(); if(c==-1) return c; } if(c=='-') return -nextInt(); int res=0; do{ res*=10; res+=c-'0'; c=System.in.read(); }while('0'<=c&&c<='9'); return res; }catch(Exception e){ return -1; } } long nextLong(){ try{ int c=System.in.read(); if(c==-1) return -1; while(c!='-'&&(c<'0'||'9'<c)){ c=System.in.read(); if(c==-1) return -1; } if(c=='-') return -nextLong(); long res=0; do{ res*=10; res+=c-'0'; c=System.in.read(); }while('0'<=c&&c<='9'); return res; }catch(Exception e){ return -1; } } double nextDouble(){ return Double.parseDouble(next()); } String next(){ try{ StringBuilder res=new StringBuilder(""); int c=System.in.read(); while(Character.isWhitespace(c)) c=System.in.read(); do{ res.append((char)c); }while(!Character.isWhitespace(c=System.in.read())); return res.toString(); }catch(Exception e){ return null; } } String nextLine(){ try{ StringBuilder res=new StringBuilder(""); int c=System.in.read(); while(c=='\r'||c=='\n') c=System.in.read(); do{ res.append((char)c); c=System.in.read(); }while(c!='\r'&&c!='\n'); return res.toString(); }catch(Exception e){ return null; } } public static void main(String[] args){ new Main().run(); } }
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
354ca85c891e7dbe5708a81bba41715f
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.*; public class _2c { static double TWO(double xx) {return xx * xx; } static double ABS(double xx) {if (xx < 0) xx = -xx; return xx;} static double tmp[] = new double [3]; static double x[] = new double [3]; static double y[] = new double [3]; static double r[] = new double [3]; static double rank(double xx, double yy) { for (int i = 0; i < 3; ++i) tmp[i] = Math.sqrt(TWO(x[i] - xx) + TWO(y[i] - yy)) / r[i]; double ret = 0; for (int i = 0; i < 3; ++i) ret += TWO(tmp[i] - tmp[(i + 1) % 3]); return ret; } static double c[][] = new double[4][2]; public static void main(String EdiTooNaive[]) { c[0][0] = 1; c[0][1] = 0; c[1][0] =-1; c[1][1] = 0; c[2][0] = 0; c[2][1] = 1; c[3][0] = 0; c[3][1] =-1; Scanner cin = new Scanner(System.in); double dx = 0, dy = 0; for (int i = 0; i < 3; ++i) { x[i] = cin.nextDouble(); y[i] = cin.nextDouble(); r[i] = cin.nextDouble(); dx += x[i]; dy += y[i]; } dx /= 3; dy /= 3; double now = rank(dx, dy); for (double d = 1; d > 1e-7; ) { boolean done = false; for (int i = 0; i < 4; ++i) { double l = dx + d * c[i][0], r = dy + d * c[i][1]; double tmp = rank(l, r); if (tmp < now) { now = tmp; dx = l; dy = r; done = true; } } if (!done) d *= 0.8; } // System.out.println(now); if (now < 1e-6) System.out.println(dx + " " + dy); } }
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
b2e2a45b70c8387336ab94457fdba6b2
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.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import java.util.Scanner; import java.util.Vector; import java.text.DecimalFormat; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author ASUS */ public class newCo { // static double x1,x2,x3,y1,y2,y3,r1,r2,r3; static double t1,t2,t3; static double[] x = new double[3]; static double[] y = new double[3]; static double[] r = new double[3]; static double[] d = new double[3]; public static double F(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 static void main(String[] args) { Scanner sc=new Scanner(System.in); double dx = 0,dy=0; for (int i = 0; i < 3; i++) { x[i] = sc.nextDouble(); y[i] = sc.nextDouble(); r[i] = sc.nextDouble(); dx += x[i]; dy += y[i]; } dx /= 3; dy /= 3; boolean f=false; double s=1; while ( s>1e-6 ) { f=false; if(F(dx,dy)>F(dx+s,dy)) {dx+=s; f=true;} else if(F(dx,dy)>F(dx-s,dy)) {dx-=s; f=true;} else if (F(dx,dy)>F(dx,dy+s)) {dy+=s; f=true;} else if (F(dx,dy)>F(dx,dy-s)) {dy-=s; f=true;} if(!f) s*=0.5; } DecimalFormat df=new DecimalFormat("0.00000"); // System.out.println(df.format(dx)+" "+dy); if (F(dx,dy)<1e-5) System.out.println(df.format(dx)+" "+df.format(dy)); else System.out.println(""); } }
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
e6c4e01f6c282a0d0d886ee63eb26383
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 CommentatorProblem { void p(int ax, int ay, int ar, int bx, int by, int br, int cx, int cy, int cr) { if (ar == br && br == cr) ll(ax, ay, ar, bx, by, br, cx, cy, cr); else if (ar == br || br == cr || ar == cr) if (br == cr) lc(cx, cy, cr, bx ,by, br, ax, ay, ar); else if (ar == cr) lc(ax, ay, ar, cx, cy, cr, bx, by, br); else lc(ax, ay, ar, bx, by, br, cx, cy, cr); else cc(ax, ay, ar, bx, by, br, cx, cy, cr); } void ll(int ax, int ay, int ar, int bx, int by, int br, int cx, int cy, int cr) { double kab = 0; if (ax != bx) kab = (ay - by) * 1.0 / (ax - bx); float mabx = (ax + bx) / 2; float maby = (ay + by) / 2; double kac = 0; if (ax != cx) kac = (ay - cy) * 1.0 / (ax - cx); float macx = (ax + cx) / 2; float macy = (ay + cy) / 2; double y = 0; double x = 0; if (ax == bx) { y = maby; x = kac*macy - kac*y + macx; } else if (ax == cx) { y = macy; x = kab*maby - kab*y + mabx; } else { y = (kab*maby + mabx - kac*macy - macx) / (kab - kac); x = kab*maby - kab*y + mabx; } System.out.println(x+" "+y); } void lc(int ax, int ay, int ar, int bx, int by, int br, int cx, int cy, int cr) { float mabx = (ax + bx) / 2; float maby = (ay + by) / 2; if (ay != by) { double k = (bx - ax) * 1.0 / (ay - by); double b = maby - k * mabx; double fa = k*k*(ar*ar-cr*cr)-(cr*cr-ar*ar); double fb = 2*(k*(b*(ar*ar-cr*cr)+ay*cr*cr-cy*ar*ar)-(ar*ar*cx-cr*cr*ax)); double fc = ar*ar*cx*cx-cr*cr*ax*ax+ar*ar*cy*cy - cr*cr*ay*ay+(ar*ar-cr*cr)*b*b + 2*(ay*cr*cr-cy*ar*ar)*b; double tmp = fb*fb - 4*fa*fc; if (tmp < 0) { return; } tmp = Math.sqrt(tmp); double x1 = (-1.0 * fb + tmp) / (2 * fa); double y1 = k * x1 + b; double x2 = (-1.0 * fb - tmp) / (2 * fa); double y2 = k * x2 + b; double d1 = Math.hypot(ax-x1, ay-y1); double d2 = Math.hypot(ax-x2, ay-y2); double angle1 = Math.asin(ar / d1); double angle2 = Math.asin(ar / d2); double y = angle1 > angle2 ? y1 : y2; double x = angle1 > angle2 ? x1 : x2; System.out.println(x+" "+y); } else { double x = mabx; double fa = cr*cr - ar*ar; double fb = 2*(cy*ar*ar - ay*cr*cr); double fc = cr*cr*ay*ay-ar*ar*cy*cy+ cr*cr*(ax-mabx)*(ax-mabx)-ar*ar*(cx-mabx)*(cx-mabx); double tmp = fb*fb - 4*fa*fc; if (tmp < 0) { return; } tmp = Math.sqrt(tmp); double y1 = (-1.0 * fb + tmp) / (2 * fa); double y2 = (-1.0 * fb - tmp) / (2 * fa); double d1 = Math.hypot(ax-x, ay-y1); double d2 = Math.hypot(ax-x, ay-y2); double angle1 = Math.asin(ar / d1); double angle2 = Math.asin(ar / d2); double y = angle1 > angle2 ? y1 : y2; System.out.println(x+" "+y); } } void cc(int ax, int ay, int ar, int bx, int by, int br, int cx, int cy, int cr) { long a = 2*((ay-cy)*br*br+(cy-by)*ar*ar+(by-ay)*cr*cr); long b = 2*(ar*ar*(bx-cx)+cr*cr*(ax-bx)+br*br*(cx-ax)); long c = ar*ar*(bx*bx+by*by-cx*cx-cy*cy) + br*br*(cx*cx+cy*cy-ax*ax-ay*ay) + cr*cr*(ax*ax+ay*ay-bx*bx-by*by); double aa = a * 1.0 / b; double cc = c * 1.0 / b; double fa = (ar*ar - br*br) * (aa*aa + 1); double fb = 2*((ay*br*br-by*ar*ar)+(ar*ar-br*br)*aa*cc-(bx*ar*ar-ax*br*br)*aa); double fc = ar*ar*bx*bx+ar*ar*by*by-br*br*ax*ax-br*br*ay*ay + (ar*ar-br*br)*cc*cc - 2*(bx*ar*ar-ax*br*br)*cc; double tmp = fb*fb - 4*fa*fc; if (tmp < 0) { return; } tmp = Math.sqrt(tmp); double y1 = (-1.0 * fb + tmp) / (2 * fa); double y2 = (-1.0 * fb - tmp) / (2 * fa); double x1 = aa * y1 + cc; double x2 = aa * y2 + cc; double d1 = Math.hypot(ax-x1, ay-y1); double d2 = Math.hypot(ax-x2, ay-y2); double angle1 = Math.asin(ar / d1); double angle2 = Math.asin(ar / d2); double y = angle1 > angle2 ? y1 : y2; double x = angle1 > angle2 ? x1 : x2; double angle = Math.max(angle1, angle2); double dc = Math.hypot(cx-x, cy-y); if (Math.asin(cr / dc) - angle > Math.pow(10, -6)) { return; } System.out.println(x+" "+y); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int ax = sc.nextInt(); int ay = sc.nextInt(); int ar = sc.nextInt(); int bx = sc.nextInt(); int by = sc.nextInt(); int br = sc.nextInt(); int cx = sc.nextInt(); int cy = sc.nextInt(); int cr = sc.nextInt(); new CommentatorProblem().p(ax, ay, ar, bx, by, br, cx, cy, cr); } }
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
62bc801780b31eed85a1b2eb777a3bde
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; /* * kab = (ay - by) / (ax - bx); * y - maby = (-1/kab) * (x - mabx); * y - macy = (-1/kac) * (x - macx); * kab*maby - kab*y + mabx = x; * kac*macy - kac*y + macx = x; * kab*maby + mabx - kac*macy - macx = (kab - kac) * y; * * double k = -1 / kab; * double b = mabx / kab + maby; * y = kx + b; * * ar / Math.hypot(ax-x, ay-y) = sinA; * cr / Math.hypot(cx-x, cy-y) = sinA; * * ar2*((cx-x)2 + (cy-y)2) = cr2*((ax-x)2 + (ay-y)2); * ar2*(cx2-2*cx*x+x2+cy2-2*cy*y+y2) = cr2*(ax2-2*ax*x+x2+ay2-2*ay*y+y2); * (ar2-cr2)*y2+2*(ay*cr2-cy*ar2)*y + ar2*cx2-cr2*ax2+ar2*cy2-cr2*ay2 * =(cr2-ar2)*x2+2*(ar2*cx-cr2*ax)*x * (ar2-cr2)*(k2*x2+2*k*b*x+b2)+2*(ay*cr2-cy*ar2)*(kx+b) + ar2*cx2-cr2*ax2+ar2*cy2-cr2*ay2 * =(cr2-ar2)*x2+2*(ar2*cx-cr2*ax)*x * (k2*(ar2-cr2)-(cr2-ar2))*x2+2*(k*(b*(ar2-cr2)+ay*cr2-cy*ar2)-(ar2*cx-cr2*ax))*x + * ar2*cx2-cr2*ax2+ar2*cy2-cr2*ay2+(ar2-cr2)*b2+2*(ay*cr2-cy*ar2)*b * * ar2*(cx-mabx)2-cr2*(ax-mabx)2=cr2*(ay2*-2*ay*y+y2)-ar2*(cy2-2*cy*y+y2); * (cr2-ar2)*y2+2*(cy*ar2-ay*cr2)*y+cr2*ay2-ar2*cy2+cr2*(ax-mabx)2-ar2*(cx-mabx)2; * * * ar / Math.hypot(ax-x, ay-y) = sinA; * br / Math.hypot(bx-x, by-y) = sinA; * cr / Math.hypot(cx-x, cy-y) = sinA; * * ar2*((bx-x)2 + (by-y)2) = br2*((ax-x)2 + (ay-y)2); * ar2*(bx2-2*bx*x+x2 + y2-2*by*y+by2) = br2*(ax2-2*ax*x+x2+ay2-2*ay*y+y2); * (ar2-br2)*y2+2*(ay*br2-by*ar2)*y+ar2*bx2+ar2*by2-br2*ax2-br2*ay2 * = (br2-ar2)*x2+2*(bx*ar2-ax*br2)*x; * * ar2*((cx-x)2 + (cy-y)2) = cr2*((ax-x)2 + (ay-y)2); * ar2*(cx2-2*cx*x+x2 + cy2-2*cy*y+y2) = cr2*(ax2-2*ax*x+x2+ay2-2*ay*y+y2); * (ar2-cr2)*y2+2*(ay*cr2-cy*ar2)*y + ar2*cx2+ar2*cy2-cr2*ax2-cr2*ay2 * = (cr2-ar2)*x2+2*(ar2*cx-cr2*ax)*x; * * 2*((ay*br2-by*ar2)*(ar2-cr2)-(ay*cr2-cy*ar2)*(ar2-br2))*y * + (ar2*bx2+ar2*by2-br2*ax2-br2*ay2)*(ar2-cr2) * - (ar2*cx2+ar2*cy2-cr2*ax2-cr2*ay2)*(ar2-br2) * = 2*((bx*ar2-ax*br2)*(ar2-cr2) - (ar2*cx-cr2*ax)*(ar2-br2))*x; * * 2*((ay*ar2*br2-by*ar4-ay*br2*cr2+by*ar2*cr2)-(ay*ar2*cr2-ay*br2*cr2-cy*ar4+cy*ar2*br2))*y * + (ar4*bx2+ar4*by2-ar2*br2*ax2-ar2*br2*ay2-ar2*cr2*bx2-ar2*cr2*by2+br2*cr2*ax2+br2*cr2*ay2) * - (ar4*cx2+ar4*cy2-ar2*cr2*ax2-ar2*cr2*ay2-ar2*br2*cx2-ar2*br2*cy2+br2*cr2*ax2+br2*cr2*ay2) * = 2*(bx*ar4-bx*ar2*cr2-ax*ar2*br2+ax*br2*cr2 - (cx*ar4-ax*ar2*cr2-cx*ar2*br2+ax*br2*cr2))*x * * 2*ar2*((ay-cy)*br2+(cy-by)*ar2+(by-ay)*cr2)*y * + ar4*(bx2+by2-cx2-cy2) + ar2*br2*(cx2+cy2-ax2-ay2) + ar2*cr2*(ax2+ay2-bx2-by2) * = 2*(ar4*(bx-cx)+ar2*cr2*(ax-bx)+ar2*br2*(cx-ax))*x * * 2*((ay-cy)*br2+(cy-by)*ar2+(by-ay)*cr2)*y * + ar2*(bx2+by2-cx2-cy2) + br2*(cx2+cy2-ax2-ay2) + cr2*(ax2+ay2-bx2-by2) * = 2*(ar2*(bx-cx)+cr2*(ax-bx)+br2*(cx-ax))*x * * x = a/b * y + c/b; * aa = a/b; * cc = c/b; * x = aa*y + cc; * * (ar2-br2)*y2+2*(ay*br2-by*ar2)*y+ar2*bx2+ar2*by2-br2*ax2-br2*ay2 * = (br2-ar2)*(a*y+c)2+2*(bx*ar2-ax*br2)*(a*y+c); * = (br2-ar2)*(a2*y2+2*a*c*y+c2)+2*(bx*ar2-ax*br2)*(a*y+c) * * (ar2-br2)*(a2+1)*y2+2*((ay*br2-by*ar2)+(ar2-br2)*a*c-(bx*ar2-ax*br2)*a)*y * + ar2*bx2+ar2*by2-br2*ax2-br2*ay2 + (ar2-br2)*c2 - 2*(bx*ar2-ax*br2)*c = 0; */ public class CommentatorProblem { void p(int ax, int ay, int ar, int bx, int by, int br, int cx, int cy, int cr) { if (ar == br && br == cr) ll(ax, ay, ar, bx, by, br, cx, cy, cr); else if (ar == br || br == cr || ar == cr) if (br == cr) lc(cx, cy, cr, bx ,by, br, ax, ay, ar); else if (ar == cr) lc(ax, ay, ar, cx, cy, cr, bx, by, br); else lc(ax, ay, ar, bx, by, br, cx, cy, cr); else cc(ax, ay, ar, bx, by, br, cx, cy, cr); } void ll(int ax, int ay, int ar, int bx, int by, int br, int cx, int cy, int cr) { double kab = 0; if (ax != bx) kab = (ay - by) * 1.0 / (ax - bx); float mabx = (ax + bx) / 2; float maby = (ay + by) / 2; double kac = 0; if (ax != cx) kac = (ay - cy) * 1.0 / (ax - cx); float macx = (ax + cx) / 2; float macy = (ay + cy) / 2; double y = 0; double x = 0; if (ax == bx) { y = maby; x = kac*macy - kac*y + macx; } else if (ax == cx) { y = macy; x = kab*maby - kab*y + mabx; } else { y = (kab*maby + mabx - kac*macy - macx) / (kab - kac); x = kab*maby - kab*y + mabx; } System.out.println(x+" "+y); } void lc(int ax, int ay, int ar, int bx, int by, int br, int cx, int cy, int cr) { float mabx = (ax + bx) / 2; float maby = (ay + by) / 2; if (ay != by) { double k = (bx - ax) * 1.0 / (ay - by); double b = maby - k * mabx; double fa = k*k*(ar*ar-cr*cr)-(cr*cr-ar*ar); double fb = 2*(k*(b*(ar*ar-cr*cr)+ay*cr*cr-cy*ar*ar)-(ar*ar*cx-cr*cr*ax)); double fc = ar*ar*cx*cx-cr*cr*ax*ax+ar*ar*cy*cy - cr*cr*ay*ay+(ar*ar-cr*cr)*b*b + 2*(ay*cr*cr-cy*ar*ar)*b; double tmp = fb*fb - 4*fa*fc; if (tmp < 0) { return; } tmp = Math.sqrt(tmp); double x1 = (-1.0 * fb + tmp) / (2 * fa); double y1 = k * x1 + b; double x2 = (-1.0 * fb - tmp) / (2 * fa); double y2 = k * x2 + b; double d1 = Math.hypot(ax-x1, ay-y1); double d2 = Math.hypot(ax-x2, ay-y2); double angle1 = Math.asin(ar / d1); double angle2 = Math.asin(ar / d2); double y = angle1 > angle2 ? y1 : y2; double x = angle1 > angle2 ? x1 : x2; System.out.println(x+" "+y); } else { double x = mabx; double fa = cr*cr - ar*ar; double fb = 2*(cy*ar*ar - ay*cr*cr); double fc = cr*cr*ay*ay-ar*ar*cy*cy+ cr*cr*(ax-mabx)*(ax-mabx)-ar*ar*(cx-mabx)*(cx-mabx); double tmp = fb*fb - 4*fa*fc; if (tmp < 0) { return; } tmp = Math.sqrt(tmp); double y1 = (-1.0 * fb + tmp) / (2 * fa); double y2 = (-1.0 * fb - tmp) / (2 * fa); double d1 = Math.hypot(ax-x, ay-y1); double d2 = Math.hypot(ax-x, ay-y2); double angle1 = Math.asin(ar / d1); double angle2 = Math.asin(ar / d2); double y = angle1 > angle2 ? y1 : y2; System.out.println(x+" "+y); } } void cc(int ax, int ay, int ar, int bx, int by, int br, int cx, int cy, int cr) { long a = 2*((ay-cy)*br*br+(cy-by)*ar*ar+(by-ay)*cr*cr); long b = 2*(ar*ar*(bx-cx)+cr*cr*(ax-bx)+br*br*(cx-ax)); long c = ar*ar*(bx*bx+by*by-cx*cx-cy*cy) + br*br*(cx*cx+cy*cy-ax*ax-ay*ay) + cr*cr*(ax*ax+ay*ay-bx*bx-by*by); double aa = a * 1.0 / b; double cc = c * 1.0 / b; double fa = (ar*ar - br*br) * (aa*aa + 1); double fb = 2*((ay*br*br-by*ar*ar)+(ar*ar-br*br)*aa*cc-(bx*ar*ar-ax*br*br)*aa); double fc = ar*ar*bx*bx+ar*ar*by*by-br*br*ax*ax-br*br*ay*ay + (ar*ar-br*br)*cc*cc - 2*(bx*ar*ar-ax*br*br)*cc; double tmp = fb*fb - 4*fa*fc; if (tmp < 0) { return; } tmp = Math.sqrt(tmp); double y1 = (-1.0 * fb + tmp) / (2 * fa); double y2 = (-1.0 * fb - tmp) / (2 * fa); double x1 = aa * y1 + cc; double x2 = aa * y2 + cc; double d1 = Math.hypot(ax-x1, ay-y1); double d2 = Math.hypot(ax-x2, ay-y2); double angle1 = Math.asin(ar / d1); double angle2 = Math.asin(ar / d2); double y = angle1 > angle2 ? y1 : y2; double x = angle1 > angle2 ? x1 : x2; double angle = Math.max(angle1, angle2); double dc = Math.hypot(cx-x, cy-y); if (Math.asin(cr / dc) - angle > Math.pow(10, -6)) { return; } System.out.println(x+" "+y); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int ax = sc.nextInt(); int ay = sc.nextInt(); int ar = sc.nextInt(); int bx = sc.nextInt(); int by = sc.nextInt(); int br = sc.nextInt(); int cx = sc.nextInt(); int cy = sc.nextInt(); int cr = sc.nextInt(); new CommentatorProblem().p(ax, ay, ar, bx, by, br, cx, cy, cr); } }
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
e1eb569bf1bec4a43a324491408c86f8
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 Commentator { public static void main(String[] args){ Scanner input = new Scanner(System.in); double x1 = input.nextDouble(); double y1 = input.nextDouble(); double r1 = input.nextInt(); double x2 = input.nextInt(); double y2 = input.nextInt(); double r2 = input.nextInt(); double x3 = input.nextInt(); double y3 = input.nextInt(); double r3 = input.nextInt(); double averageX = average(x1, x2, x3); double averageY = average(y1, y2, y3); double c[][] = new double[4][2]; c[0][0] = 1; c[0][1] = 0; c[1][0] =-1; c[1][1] = 0; c[2][0] = 0; c[2][1] = 1; c[3][0] = 0; c[3][1] =-1; double d1 = Math.sqrt(TWO(averageX - x1) + TWO(averageY - y1)); double d2 = Math.sqrt(TWO(averageX - x2) + TWO(averageY - y2)); double d3 = Math.sqrt(TWO(averageX - x3) + TWO(averageY - y3)); double substract = TWO(r1 / r2 - d1 / d2) + TWO(r1 / r3 - d1 / d3) + TWO(r2 / r3 - d2 / d3); for(double d = 1; d > 1e-7;){ boolean done = false; for(int i = 0; i < 4 ; i++){ double y = averageY + d * c[i][0]; double x = averageX + d * c[i][1]; d1 = Math.sqrt(TWO(x - x1) + TWO(y - y1)); d2 = Math.sqrt(TWO(x - x2) + TWO(y - y2)); d3 = Math.sqrt(TWO(x - x3) + TWO(y - y3)); double newSubstract = TWO(r1 / r2 - d1 / d2 )+ TWO(r1 / r3 - d1 / d3) + TWO(r2 / r3 - d2 / d3); if(newSubstract < substract){ substract = newSubstract; averageX = x; averageY = y; done = true; } } if(!done){ d *= 0.8; } } if (substract < 1e-6)System.out.printf("%.5f"+" "+"%.5f",averageX,averageY); } public static double average(double x, double y ,double z){ double average = (x + y + z) / 3.0; return average; } public static double TWO(double x){ return x * x; } }
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
3d8037d0f81545edeb9ccfb43f6da9c2
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; import static java.lang.Math.*; public class CCommentatorProblem { public static double g(double u, double v, int[] x, int[] y, int[] r) { double f1 = sqrt(pow(u - x[0], 2) + pow(v - y[0], 2)) - sqrt(pow(u - x[1], 2) + pow(v - y[1], 2)) * r[0] / r[1]; double f2 = sqrt(pow(u - x[0], 2) + pow(v - y[0], 2)) - sqrt(pow(u - x[2], 2) + pow(v - y[2], 2)) * r[0] / r[2]; return pow(f1, 2) + pow(f2, 2); } public static void main(String[] args) { Scanner in = new Scanner(System.in); int[] x = new int[3]; int[] y = new int[3]; int[] r = new int[3]; for (int i = 0; i < 3; i++) { x[i] = in.nextInt(); y[i] = in.nextInt(); r[i] = in.nextInt(); } int[][] e = { { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 } }; double step = 1; double eps = 1e-6; double u = (x[0] + x[1] + x[2]) / 3.0; double v = (y[0] + y[1] + y[2]) / 3.0; double prev = g(u, v, x, y, r); while (step > eps) { int dir = -1; double minCurr = 0; double diff = 0; for (int i = 0; i < 4; i++) { double curr = g(u + e[i][0] * step, v + e[i][1] * step, x, y, r); if (curr - prev < diff) { dir = i; diff = curr - prev; minCurr = curr; } } if (dir == -1) { step *= 0.5; } else { // System.out.println(minCurr); prev = minCurr; u = u + e[dir][0] * step; v = v + e[dir][1] * step; } } if (prev < eps) System.out.println(u + " " + v); } }
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
fae2896a7e16a51cfcdcafa7fe4c7a2c
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 static String taskname = "filename"; 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)); // in = new BufferedReader(new FileReader(taskname + ".in")); // out = new BufferedWriter(new FileWriter(taskname + ".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 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
189cdcd2c2bbf56e17a6c9f4da663f85
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.util.*; import java.lang.*; import java.io.*; import java.math.*; public class Main { static final double EPS = 1e-6; static class Point { double x, y; Point(double x, double y) { this.x = x; this.y = y; } 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); } Point mul(double f) { return new Point(x * f, y * f); } Point rotate(double cos, double sin) { return new Point(x * cos - y * sin, x * sin + y * cos); } double len() { return Math.hypot(x, y); } double dist(Point p) { return Math.hypot(x - p.x, y - p.y); } public String toString() { return x + " " + y; } } static 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 Math.abs(a * p.x + b * p.y + c) / Math.sqrt(a * a + b * b); } public String toString() { return a + " " + b + " " + c; } } static class Circle { Point center; double r; Circle(double x, double y, double r) { center = new Point(x, y); this.r = r; } public String toString() { return center + " " + r; } } public static void main(String[] args) throws IOException { Scanner input = new Scanner(System.in); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); Circle c1, c2, c3; c1 = new Circle(input.nextInt(), input.nextInt(), input.nextInt()); c2 = new Circle(input.nextInt(), input.nextInt(), input.nextInt()); c3 = new Circle(input.nextInt(), input.nextInt(), input.nextInt()); Point res = null; if (c1.r == c2.r) { if (c1.r == c3.r) { res = intersect(getLine(c1, c2), getLine(c1, c3)); } else { res = getBest(intersect(getCircle(c1, c3), getLine(c1, c2)), c1); } } else { if (c1.r == c3.r) { res = getBest(intersect(getCircle(c1, c2), getLine(c1, c3)), c1); } else { res = getBest(intersect(getCircle(c1, c2), getCircle(c1, c3)), c1); } } if (res != null) out.printf("%.6f %.6f", res.x, res.y); out.close(); } static Line getLine(Circle c1, Circle c2) { return new Line(c1.center.x, c1.center.y, c2.center.x, c2.center.y).getNormal((c1.center.x + c2.center.x) / 2, (c1.center.y + c2.center.y) / 2); } static Circle getCircle(Circle c1, Circle c2) { Point vectorAB = c2.center.sub(c1.center); double factor = c1.r / (c1.r + c2.r); Point p1 = c1.center.add(vectorAB.mul(factor)); Point p2; if (c1.r < c2.r) { p2 = c1.center.sub(vectorAB.mul(c1.r / (c2.r - c1.r))); } else { p2 = c2.center.add(vectorAB.mul(c2.r / (c1.r - c2.r))); } return new Circle((p1.x + p2.x) / 2, (p1.y + p2.y) / 2, p1.dist(p2) / 2); } static Point getBest(Point[] p, Circle c) { if (p == null) return null; double minD = 1e30; Point ret = null; for (int i = 0; i < p.length; ++i) { if (minD > c.center.dist(p[i])) { minD = c.center.dist(p[i]); ret = p[i]; } } return ret; } static Point[] intersect(Circle c1, Circle c2) { double distAB = c1.center.dist(c2.center); Point vector = c2.center.sub(c1.center).mul(c1.r / distAB); if (Math.abs(c1.r - c2.r) - distAB > EPS || distAB - (c1.r + c2.r) > EPS) return null; double cos = (c1.r * c1.r + distAB * distAB - c2.r * c2.r) / (2 * c1.r * distAB); double sin = Math.sqrt(1 - cos * cos); return new Point[] { c1.center.add(vector.rotate(cos, sin)), c1.center.add(vector.rotate(cos, -sin)) }; } static Point[] intersect(Circle c, Line l) { double dist = l.dist(c.center); if (dist > c.r) return null; Point vectorN = new Point(l.a, l.b); Point p1 = c.center.add(vectorN); Point p2 = c.center.sub(vectorN); Point p = null; if (l.dist(p1) < l.dist(p2)) p = p1; else p = p2; Point vector = p.sub(c.center).mul(c.r / vectorN.len()); double cos = dist / c.r; double sin = Math.sqrt(1 - cos * cos); return new Point[] { c.center.add(vector.rotate(cos, sin)), c.center.add(vector.rotate(cos, -sin)) }; } static Point intersect(Line l1, Line l2) { double d = l1.a * l2.b - l1.b * l2.a; double dx = l1.b * l2.c - l1.c * l2.b; double dy = l1.c * l2.a - l1.a * l2.c; return new Point(dx / d, dy / d); } void check(boolean b) { if (b) return; System.out.println(new Error().getStackTrace()[1]); System.exit(999); } }
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
fb84d9b166d9d31b33303007e56e09ca
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.io.PrintWriter; import java.util.StringTokenizer; public class L implements Runnable { static String hack = "public class X "; static final double EPS = 1e-5; public static void main(String[] args) { new Thread(new L()).start(); } public void run() { try { solve(); } catch (IOException e) { throw new RuntimeException(e); } } BufferedReader br; StringTokenizer st = new StringTokenizer(""); static class Point { final double x, y; Point(double x, double y) { this.x = x; this.y = y; } @Override public String toString() { return "(" + x + ", " + y + ")"; } } static abstract class Shape { } static class Line extends Shape { final Point p; final Point v; Line(Point p, Point v) { this.p = p; this.v = v; } } static class Circle extends Shape { final Point c; final double r; Circle(Point c, double r) { this.c = c; this.r = r; } @Override public String toString() { return "Circle{" + "c=" + c + ", r=" + r + '}'; } } void solve() throws IOException { br = new BufferedReader(new InputStreamReader(System.in)); Circle c1 = nextCircle(); Circle c2 = nextCircle(); Circle c3 = nextCircle(); br.close(); Shape s12 = equiliblirium(c1, c2); Shape s13 = equiliblirium(c1, c3); Point[] commonPoints = intersect(s12, s13); double leastDistPow2 = Double.MAX_VALUE; Point ans = null; for (Point commonPoint : commonPoints) { double currDistPow2 = dist2(commonPoint, c1.c); if (currDistPow2 < leastDistPow2) { leastDistPow2 = currDistPow2; ans = commonPoint; } } PrintWriter pw = new PrintWriter(System.out); if (ans != null) { pw.printf("%.5f %.5f\n", ans.x, ans.y); } pw.close(); } Point[] intersect(Shape s1, Shape s2) { if (s1 instanceof Line && s2 instanceof Line) { return intersectLineLine((Line) s1, (Line) s2); } if (s1 instanceof Circle && s2 instanceof Circle) { return intersectCircleCircle((Circle) s1, (Circle) s2); } if (s1 instanceof Circle) { return intersectCircleLine((Circle) s1, (Line) s2); } else { return intersectCircleLine((Circle) s2, (Line) s1); } } Point[] intersectCircleLine(Circle circle, Line line) { Point[] ii = intersectLineLine(line, new Line(circle.c, rotate90Clockwise(line.v))); Point ip = ii[0]; double d2 = dist2(circle.c, ip); if (pow2(circle.r) + EPS < d2) { return new Point[] {}; } double up = Math.sqrt(Math.abs(pow2(circle.r) - d2)); Point v = resize(line.v, up); return new Point[] { add(ip, v), add(ip, multiply(v, -1)) }; } Point[] intersectCircleCircle(Circle circle1, Circle circle2) { final Point c1 = circle1.c, c2 = circle2.c; final double r1 = circle1.r, r2 = circle2.r; final double l2 = dist2(c1, c2); final double l = Math.sqrt(l2); if (r1 + r2 + EPS < l) { return new Point[] {}; } if (l + Math.min(r1, r2) + EPS < Math.max(r1, r2)) { return new Point[] {}; } double l1 = (pow2(r1) - pow2(r2) + l2) / (2 * l); double up1 = Math.sqrt(Math.abs(pow2(r1) - pow2(l1))); Point v = normalize(v(c1, c2)); Point q = add(c1, multiply(v, l1)); Point vp = multiply(rotate90Clockwise(v), up1); return new Point[] { add(q, vp), add(q, multiply(vp, -1)) }; } Point[] intersectLineLine(Line line1, Line line2) { double det = det( line1.v.x, -line2.v.x, line1.v.y, -line2.v.y ); if (Math.abs(det) < EPS) { return new Point[] {}; } double t1 = det( line2.p.x - line1.p.x, -line2.v.x, line2.p.y - line1.p.y, -line2.v.y ); t1 /= det; Point i = add(line1.p, multiply(line1.v, t1)); return new Point[] {i}; } Shape equiliblirium(Circle c1, Circle c2) { if (Math.abs(c1.r - c2.r) > 0.5) { return buildCenterCircle(c1, c2); } return buildCenterLine(c1, c2); } Shape buildCenterCircle(Circle c1, Circle c2) { double r1pow2 = pow2(c1.r), r2pow2 = pow2(c2.r); double x1 = c1.c.x, y1 = c1.c.y, x2 = c2.c.x, y2 = c2.c.y; double denom = r2pow2 - r1pow2; double ax = 2 * (x2 * r1pow2 - x1 * r2pow2) / denom; double ay = 2 * (y2 * r1pow2 - y1 * r2pow2) / denom; double a = (r1pow2 * (pow2(x2) + pow2(y2)) - r2pow2 * (pow2(x1) + pow2(y1))) / denom; double xi = -ax / 2; double yi = -ay / 2; double riPow2 = a + pow2(xi) + pow2(yi); if (riPow2 < EPS) { throw new RuntimeException("BOTVA"); } double ri = Math.sqrt(riPow2); return new Circle(new Point(xi, yi), ri); } Line buildCenterLine(Circle c1, Circle c2) { Point v = v(c1.c, c2.c); Point center = multiply(add(c1.c, c2.c), 0.5); return new Line(center, rotate90Clockwise(v)); } static double pow2(double x) { return x * x; } static double det(double a11, double a12, double a21, double a22) { return a11 * a22 - a12 * a21; } static Point v(Point from, Point to) { return new Point(to.x - from.x, to.y - from.y); } static Point add(Point p, Point v) { return new Point(p.x + v.x, p.y + v.y); } static Point multiply(Point v, double k) { return new Point(v.x * k, v.y * k); } static Point resize(Point v, double length) { return multiply(normalize(v), length); } static Point rotate90Clockwise(Point v) { return new Point(v.y, -v.x); } static double dist(Point a, Point b) { return Math.sqrt(dist2(a, b)); } static double dist2(Point a, Point b) { return pow2(a.x - b.x) + pow2(a.y - b.y); } static Point normalize(Point v) { double l = dist(new Point(0, 0), v); return new Point(v.x / l, v.y / l); } Circle nextCircle() throws IOException { int x = nextInt(); int y = nextInt(); int r = nextInt(); return new Circle(new Point(x, y), r); } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } String nextToken() throws IOException { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }
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
52f8d62af777ee6e40baed5abb1e7e91
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.*; import java.math.*; import java.text.*; public class Main { static final int MAXN = 1005; static final int MAXM = 1000005; static final int MOD = 10000; static final int INF = 1000000000; static final double EPS = 1E-6; Point[] p = new Point[3]; double[] ang = new double[3]; int[][] dir = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}}; void init() { } double getDis(double x1, double y1, double x2, double y2) { return Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); } double assess(double x, double y) { double dif; for (int i = 0; i < 3; i++) ang[i] = getDis(x, y, p[i].x, p[i].y) / p[i].r; dif = 0; for (int i = 0; i < 3; i++) for (int j = i + 1; j < 3; j++) dif += (ang[i] - ang[j]) * (ang[i] - ang[j]); return dif; } void run() { double delta = 1, x = 0, y = 0, cur, last; for (int i = 0; i < 3; i++) { p[i] = new Point(cin.nextDouble(), cin.nextDouble(), cin.nextDouble()); x += p[i].x; y += p[i].y; } x /= 3; y /= 3; int i; while (delta > EPS) { last = assess(x, y); for (i = 0; i < 4; i++) { double dx = x + delta * dir[i][0], dy = y + delta * dir[i][1]; cur = assess(dx, dy); if (cur < last) { break; } } if (i >= 4) { delta *= 0.75; } else { x += delta * dir[i][0]; y += delta * dir[i][1]; } } if (assess(x, y) < EPS) System.out.printf("%.5f %.5f\n", x, y); } public static void main(String[] args) { Main solved = new Main(); solved.run(); } Scanner cin = new Scanner(new BufferedInputStream(System.in)); } class Point { double x, y, r; Point() {} Point(double x, double y, double r) { this.x = x; this.y = y; this.r = r; } }
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
84792a1f6cf6addd589537653223c652
train_000.jsonl
1518705300
For a permutation P[1... N] of integers from 1 to N, function f is defined as follows: Let g(i) be the minimum positive integer j such that f(i, j) = i. We can show such j always exists.For given N, A, B, find a permutation P of integers from 1 to N such that for 1 ≤ i ≤ N, g(i) equals either A or B.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; public class Main { static Scanner cin = new Scanner(System.in); public static void main(String[] args) throws IOException { int n = cin.nextInt(); int A = cin.nextInt(); int B = cin.nextInt(); int[] p = new int[n + 1]; int index = 1; int num = n; while(true){ if(num % A == 0){ int t = num / A; while(t-- > 0){ p[index] = index + A - 1; for(int i = index + A - 1;i > index;i --){ p[i] = i - 1; } index += A; } num = 0; break; } else if(num % B == 0){ int t = num / B; while(t-- > 0){ p[index] = index + B - 1; for(int i = index + B - 1;i > index;i --){ p[i] = i - 1; } index += B; } num = 0; break; } else { if(index + A > n) break; p[index] = index + A - 1; for(int i = index + A - 1;i > index;i --){ p[i] = i - 1; } index += A; num -= A; } } StringBuilder res = new StringBuilder(); if(num == 0){ for(int i = 1;i <= n;i++){ res.append(p[i]); // System.out.print(p[i]); if(i == n) res.append('\n'); // System.out.print('\n'); else res.append(' '); // System.out.print(' '); } System.out.print(res); } else System.out.println(-1); } } class Reader { private static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); private static StringTokenizer tokenizer = new StringTokenizer(""); static String nextLine() throws IOException{ return reader.readLine(); } private static String next() throws IOException { while (!tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } return tokenizer.nextToken(); } static int nextInt() throws IOException { return Integer.parseInt(next()); } static double nextDouble() throws IOException { return Double.parseDouble(next()); } }
Java
["9 2 5", "3 2 1"]
2 seconds
["6 5 8 3 4 1 9 2 7", "1 2 3"]
NoteIn the first example, g(1) = g(6) = g(7) = g(9) = 2 and g(2) = g(3) = g(4) = g(5) = g(8) = 5 In the second example, g(1) = g(2) = g(3) = 1
Java 11
standard input
[ "constructive algorithms", "brute force" ]
138f7db4a858fb1efe817ee6491f83d9
The only line contains three integers N, A, B (1 ≤ N ≤ 106, 1 ≤ A, B ≤ N).
1,600
If no such permutation exists, output -1. Otherwise, output a permutation of integers from 1 to N.
standard output
PASSED
2a98c8133da46b66c1bbe9f8cda58568
train_000.jsonl
1518705300
For a permutation P[1... N] of integers from 1 to N, function f is defined as follows: Let g(i) be the minimum positive integer j such that f(i, j) = i. We can show such j always exists.For given N, A, B, find a permutation P of integers from 1 to N such that for 1 ≤ i ≤ N, g(i) equals either A or B.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException { int n = Reader.nextInt(); int A = Reader.nextInt(); int B = Reader.nextInt(); int[] p = new int[n + 1]; int index = 1; int num = n; while(true){ if(num % A == 0){ int t = num / A; while(t-- > 0){ p[index] = index + A - 1; for(int i = index + A - 1;i > index;i --){ p[i] = i - 1; } index += A; } num = 0; break; } else if(num % B == 0){ int t = num / B; while(t-- > 0){ p[index] = index + B - 1; for(int i = index + B - 1;i > index;i --){ p[i] = i - 1; } index += B; } num = 0; break; } else { if(index + A > n) break; p[index] = index + A - 1; for(int i = index + A - 1;i > index;i --){ p[i] = i - 1; } index += A; num -= A; } } StringBuilder res = new StringBuilder(); if(num == 0){ for(int i = 1;i <= n;i++){ res.append(p[i]); // System.out.print(p[i]); if(i == n) res.append('\n'); // System.out.print('\n'); else res.append(' '); // System.out.print(' '); } System.out.print(res); } else System.out.println(-1); } } class Reader { private static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); private static StringTokenizer tokenizer = new StringTokenizer(""); static String nextLine() throws IOException{ return reader.readLine(); } private static String next() throws IOException { while (!tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } return tokenizer.nextToken(); } static int nextInt() throws IOException { return Integer.parseInt(next()); } static double nextDouble() throws IOException { return Double.parseDouble(next()); } }
Java
["9 2 5", "3 2 1"]
2 seconds
["6 5 8 3 4 1 9 2 7", "1 2 3"]
NoteIn the first example, g(1) = g(6) = g(7) = g(9) = 2 and g(2) = g(3) = g(4) = g(5) = g(8) = 5 In the second example, g(1) = g(2) = g(3) = 1
Java 11
standard input
[ "constructive algorithms", "brute force" ]
138f7db4a858fb1efe817ee6491f83d9
The only line contains three integers N, A, B (1 ≤ N ≤ 106, 1 ≤ A, B ≤ N).
1,600
If no such permutation exists, output -1. Otherwise, output a permutation of integers from 1 to N.
standard output
PASSED
8ba88a6ed3bb843e065a2444453e2eae
train_000.jsonl
1359732600
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle a.Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to a?
256 megabytes
import java.util.*; public class Solution { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); for (int i = 0; i < t; i++) { int a = scanner.nextInt(); if (a < 60) { System.out.println("NO"); } else if (360 % (180 - a) == 0) { System.out.println("YES"); } else { System.out.println("NO"); } } } }
Java
["3\n30\n60\n90"]
2 seconds
["NO\nYES\nYES"]
NoteIn the first test case, it is impossible to build the fence, since there is no regular polygon with angle .In the second test case, the fence is a regular triangle, and in the last test case — a square.
Java 8
standard input
[ "implementation", "geometry", "math" ]
9037f487a426ead347baa803955b2c00
The first line of input contains an integer t (0 &lt; t &lt; 180) — the number of tests. Each of the following t lines contains a single integer a (0 &lt; a &lt; 180) — the angle the robot can make corners at measured in degrees.
1,100
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
standard output
PASSED
71e59fe48b9af6011a0b75e5cf35e60d
train_000.jsonl
1359732600
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle a.Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to a?
256 megabytes
import java.util.*; import java.lang.Math; public class hello { public static void main (String[] args) throws java.lang.Exception { Scanner scan = new Scanner(System.in); int ans = 0; int a = scan.nextInt(); ArrayList<Double> list = new ArrayList<Double>(); String[] output = new String[a]; double sides = 3; while(sides <= 360) { list.add((sides-2)*180/sides); sides++; } int[] nums = new int[a]; for(int i = 0; i < a; i++) { scan.nextLine(); nums[i] = scan.nextInt(); if(list.contains((double)nums[i])) { output[i] = "YES"; } else { output[i] = "NO"; } } for(String str : output) { System.out.println(str); } } }
Java
["3\n30\n60\n90"]
2 seconds
["NO\nYES\nYES"]
NoteIn the first test case, it is impossible to build the fence, since there is no regular polygon with angle .In the second test case, the fence is a regular triangle, and in the last test case — a square.
Java 8
standard input
[ "implementation", "geometry", "math" ]
9037f487a426ead347baa803955b2c00
The first line of input contains an integer t (0 &lt; t &lt; 180) — the number of tests. Each of the following t lines contains a single integer a (0 &lt; a &lt; 180) — the angle the robot can make corners at measured in degrees.
1,100
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
standard output
PASSED
4fc89b0d778f4f47471899a3b3aee9de
train_000.jsonl
1359732600
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle a.Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to a?
256 megabytes
import java.util.*; public class _270A_Fancy_Fence { public static void main(String[] args) { Scanner input= new Scanner (System.in); int n= input.nextInt(),i; int a[]= new int[n]; for (i=0;i<n;i++) a[i]= input.nextInt(); for (i=0;i<n;i++) { if(360%(180-a[i])==0) System.out.println("YES"); else System.out.println("NO"); } input.close(); } }
Java
["3\n30\n60\n90"]
2 seconds
["NO\nYES\nYES"]
NoteIn the first test case, it is impossible to build the fence, since there is no regular polygon with angle .In the second test case, the fence is a regular triangle, and in the last test case — a square.
Java 8
standard input
[ "implementation", "geometry", "math" ]
9037f487a426ead347baa803955b2c00
The first line of input contains an integer t (0 &lt; t &lt; 180) — the number of tests. Each of the following t lines contains a single integer a (0 &lt; a &lt; 180) — the angle the robot can make corners at measured in degrees.
1,100
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
standard output
PASSED
7f1145fbff79056efd5e8f45072313d8
train_000.jsonl
1359732600
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle a.Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to a?
256 megabytes
import java.util.*; public class _270A_Fancy_Fence { public static void main(String[] args) { Scanner input= new Scanner (System.in); int n= input.nextInt(),i; int a[]= new int[n]; for (i=0;i<n;i++) { a[i]= input.nextInt(); if(360%(180-a[i])==0) System.out.println("YES"); else System.out.println("NO"); } input.close(); } }
Java
["3\n30\n60\n90"]
2 seconds
["NO\nYES\nYES"]
NoteIn the first test case, it is impossible to build the fence, since there is no regular polygon with angle .In the second test case, the fence is a regular triangle, and in the last test case — a square.
Java 8
standard input
[ "implementation", "geometry", "math" ]
9037f487a426ead347baa803955b2c00
The first line of input contains an integer t (0 &lt; t &lt; 180) — the number of tests. Each of the following t lines contains a single integer a (0 &lt; a &lt; 180) — the angle the robot can make corners at measured in degrees.
1,100
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
standard output
PASSED
d6f13ae8649d9dec1134c187bfc2c2e3
train_000.jsonl
1359732600
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle a.Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to a?
256 megabytes
import java.util.*; public class Solution{ public static void main (String args[]){ Scanner sc = new Scanner (System.in); int t = sc.nextInt(); while (t --> 0){ int a = sc.nextInt(); int s = a - 180; int ans = -360%s; if (ans != 0){ System.out.println("NO"); } else{ System.out.println("YES"); } } } }
Java
["3\n30\n60\n90"]
2 seconds
["NO\nYES\nYES"]
NoteIn the first test case, it is impossible to build the fence, since there is no regular polygon with angle .In the second test case, the fence is a regular triangle, and in the last test case — a square.
Java 8
standard input
[ "implementation", "geometry", "math" ]
9037f487a426ead347baa803955b2c00
The first line of input contains an integer t (0 &lt; t &lt; 180) — the number of tests. Each of the following t lines contains a single integer a (0 &lt; a &lt; 180) — the angle the robot can make corners at measured in degrees.
1,100
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
standard output
PASSED
7f7e0575295f984361423547fdd3044b
train_000.jsonl
1359732600
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle a.Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to a?
256 megabytes
import java.io.InputStream; import java.io.InputStreamReader; import java.util.HashMap; import java.io.BufferedReader; import java.util.Map; import java.io.OutputStream; import java.io.PrintWriter; import java.io.IOException; import java.util.StringTokenizer; import java.util.Arrays; import java.util.PriorityQueue; public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); int n = in.nextInt(); int[] a = ARRTools.readArray(in, n); float[] k = ARRTools.polyArray(360); boolean accept = false; for(int i = 0; i < n; i++){ accept = false;; for(int j = 0; j < 357; j++){ if(a[i] == k[j] || a[i] == 179){ out.println("YES"); accept = true; break; } } if(accept == false){ out.println("NO"); } } out.close(); } } class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } public long nextLong(){ return Long.parseLong(next()); } } class ARRTools { public static int[] readArray(InputReader in, int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) array[i] = in.nextInt(); return array; } public static float[] polyArray(int size){ float[] array = new float[size-2]; for(float i = 3; i < size; i++){ array[(int)i-3] = (180*(i-2))/i; } return array; } }
Java
["3\n30\n60\n90"]
2 seconds
["NO\nYES\nYES"]
NoteIn the first test case, it is impossible to build the fence, since there is no regular polygon with angle .In the second test case, the fence is a regular triangle, and in the last test case — a square.
Java 8
standard input
[ "implementation", "geometry", "math" ]
9037f487a426ead347baa803955b2c00
The first line of input contains an integer t (0 &lt; t &lt; 180) — the number of tests. Each of the following t lines contains a single integer a (0 &lt; a &lt; 180) — the angle the robot can make corners at measured in degrees.
1,100
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
standard output
PASSED
3a49ac6107c3f40fc332014580d83563
train_000.jsonl
1359732600
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle a.Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to a?
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); for (int t = in.nextInt(); t --> 0 ;) { int a = in.nextInt(); boolean x = false; int c = a + a; for (int i = 3; i < 1000000; ++i) { c += a; if ((i - 2) * 180L == c) { x = true; break; } } if (x) { System.out.println("YES"); } else { System.out.println("NO"); } } } }
Java
["3\n30\n60\n90"]
2 seconds
["NO\nYES\nYES"]
NoteIn the first test case, it is impossible to build the fence, since there is no regular polygon with angle .In the second test case, the fence is a regular triangle, and in the last test case — a square.
Java 8
standard input
[ "implementation", "geometry", "math" ]
9037f487a426ead347baa803955b2c00
The first line of input contains an integer t (0 &lt; t &lt; 180) — the number of tests. Each of the following t lines contains a single integer a (0 &lt; a &lt; 180) — the angle the robot can make corners at measured in degrees.
1,100
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
standard output
PASSED
98a830ff7f0ddb3d80300d99def85ffa
train_000.jsonl
1359732600
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle a.Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to a?
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for(int i = 0; i < n; i++){ int a = sc.nextInt(); int x = 360 / (180 - a); if(x * (180 - a) == 360){ System.out.println("YES"); } else{ System.out.println("NO"); } } sc.close(); } }
Java
["3\n30\n60\n90"]
2 seconds
["NO\nYES\nYES"]
NoteIn the first test case, it is impossible to build the fence, since there is no regular polygon with angle .In the second test case, the fence is a regular triangle, and in the last test case — a square.
Java 8
standard input
[ "implementation", "geometry", "math" ]
9037f487a426ead347baa803955b2c00
The first line of input contains an integer t (0 &lt; t &lt; 180) — the number of tests. Each of the following t lines contains a single integer a (0 &lt; a &lt; 180) — the angle the robot can make corners at measured in degrees.
1,100
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
standard output
PASSED
6b59e947de4ab90d6566fe4a1ea2fea6
train_000.jsonl
1359732600
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle a.Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to a?
256 megabytes
import java.util.Scanner; public class A270 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] array = new int[n]; for (int i = 0; i < n; i++) { array[i] = sc.nextInt(); } for (int i = 0; i < n; i++) { if (array[i] == 180) { System.out.println("NO"); } else { if (array[i] >= 60) { if ((360%(180 - array[i])) == 0) { System.out.println("YES"); } else { System.out.println("NO"); } } else { System.out.println("NO"); } } } } }
Java
["3\n30\n60\n90"]
2 seconds
["NO\nYES\nYES"]
NoteIn the first test case, it is impossible to build the fence, since there is no regular polygon with angle .In the second test case, the fence is a regular triangle, and in the last test case — a square.
Java 8
standard input
[ "implementation", "geometry", "math" ]
9037f487a426ead347baa803955b2c00
The first line of input contains an integer t (0 &lt; t &lt; 180) — the number of tests. Each of the following t lines contains a single integer a (0 &lt; a &lt; 180) — the angle the robot can make corners at measured in degrees.
1,100
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
standard output
PASSED
c05c3f0350436b258c750e437021edcd
train_000.jsonl
1359732600
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle a.Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to a?
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n= sc.nextInt(); int a[]=new int[n]; for(int i=0;i<n;i++){ a[i]=sc.nextInt(); } for(int i=0;i<n;i++){ if(360%(180-a[i])==0) System.out.println("YES"); else System.out.println("NO"); } } }
Java
["3\n30\n60\n90"]
2 seconds
["NO\nYES\nYES"]
NoteIn the first test case, it is impossible to build the fence, since there is no regular polygon with angle .In the second test case, the fence is a regular triangle, and in the last test case — a square.
Java 8
standard input
[ "implementation", "geometry", "math" ]
9037f487a426ead347baa803955b2c00
The first line of input contains an integer t (0 &lt; t &lt; 180) — the number of tests. Each of the following t lines contains a single integer a (0 &lt; a &lt; 180) — the angle the robot can make corners at measured in degrees.
1,100
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
standard output
PASSED
341233ccd5ddc70bdfb6794999229cb5
train_000.jsonl
1359732600
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle a.Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to a?
256 megabytes
import java.util.Scanner; public class FancyFence { public static void main(String[] args) { Scanner z=new Scanner(System.in); int t=z.nextInt(); int a[]=new int[t]; String aa[]=new String[t]; for(int i=0;i<a.length;i++) a[i]=z.nextInt(); for(int i=0;i<a.length;i++) { int temp=0; boolean flag=false; while(temp<=360){ if(temp==360){ flag=true; break; } temp+=180-a[i]; } if(flag) aa[i]="YES"; else aa[i]="NO"; } for(String xx:aa) System.out.println(xx); } }
Java
["3\n30\n60\n90"]
2 seconds
["NO\nYES\nYES"]
NoteIn the first test case, it is impossible to build the fence, since there is no regular polygon with angle .In the second test case, the fence is a regular triangle, and in the last test case — a square.
Java 8
standard input
[ "implementation", "geometry", "math" ]
9037f487a426ead347baa803955b2c00
The first line of input contains an integer t (0 &lt; t &lt; 180) — the number of tests. Each of the following t lines contains a single integer a (0 &lt; a &lt; 180) — the angle the robot can make corners at measured in degrees.
1,100
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
standard output
PASSED
c2f972dbb80d330d7fc90dcd03bc1511
train_000.jsonl
1359732600
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle a.Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to a?
256 megabytes
import java.util.Scanner; public class AFancyFence { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); //System.out.println(n); String t = scanner.nextLine(); int a; double[] brStrana = new double[361]; brStrana[0] = 0; brStrana[1] = 0; brStrana[2] = 0; int brojac = 0; boolean flag = false; for(int i = 3; i < 361; i++) { double k = ((i-2)*180.0)/i; brStrana[i] = k; } for(int i = 0; i < 361; i++) { if(brStrana[i] == Math.floor(brStrana[i])) continue; else { brStrana[i] = 0; } } for(int i = 0; i < n; i++) { flag = false; a = scanner.nextInt(); t = scanner.nextLine(); // System.out.println(a); for(int j = 0; j < 361; j++) { if(a == Math.floor(brStrana[j])) flag = true; } if(flag) System.out.println("YES"); else System.out.println("NO"); } } }
Java
["3\n30\n60\n90"]
2 seconds
["NO\nYES\nYES"]
NoteIn the first test case, it is impossible to build the fence, since there is no regular polygon with angle .In the second test case, the fence is a regular triangle, and in the last test case — a square.
Java 8
standard input
[ "implementation", "geometry", "math" ]
9037f487a426ead347baa803955b2c00
The first line of input contains an integer t (0 &lt; t &lt; 180) — the number of tests. Each of the following t lines contains a single integer a (0 &lt; a &lt; 180) — the angle the robot can make corners at measured in degrees.
1,100
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
standard output
PASSED
d0d3f3727a84544e4754f2b798c08cfa
train_000.jsonl
1359732600
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle a.Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to a?
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for(int i = 0; i < t; i++) { int a = sc.nextInt(); double n = 360/(180.0-a); if(n==Math.floor(n)) System.out.println("YES"); else System.out.println("NO"); } } }
Java
["3\n30\n60\n90"]
2 seconds
["NO\nYES\nYES"]
NoteIn the first test case, it is impossible to build the fence, since there is no regular polygon with angle .In the second test case, the fence is a regular triangle, and in the last test case — a square.
Java 8
standard input
[ "implementation", "geometry", "math" ]
9037f487a426ead347baa803955b2c00
The first line of input contains an integer t (0 &lt; t &lt; 180) — the number of tests. Each of the following t lines contains a single integer a (0 &lt; a &lt; 180) — the angle the robot can make corners at measured in degrees.
1,100
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
standard output
PASSED
dc7c94813f1f0dec5ad87e5da2263d60
train_000.jsonl
1359732600
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle a.Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to a?
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for(int i = 0; i < t; i++) { int a = sc.nextInt(); double n = 360/(180.0-a); if(n==Math.floor(n)) System.out.println("YES"); else System.out.println("NO"); } } }
Java
["3\n30\n60\n90"]
2 seconds
["NO\nYES\nYES"]
NoteIn the first test case, it is impossible to build the fence, since there is no regular polygon with angle .In the second test case, the fence is a regular triangle, and in the last test case — a square.
Java 8
standard input
[ "implementation", "geometry", "math" ]
9037f487a426ead347baa803955b2c00
The first line of input contains an integer t (0 &lt; t &lt; 180) — the number of tests. Each of the following t lines contains a single integer a (0 &lt; a &lt; 180) — the angle the robot can make corners at measured in degrees.
1,100
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
standard output
PASSED
5564d363210833d6c1ed724b23d2cba9
train_000.jsonl
1359732600
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle a.Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to a?
256 megabytes
import java.util.Scanner; public class FancyFence { public static void main(String[] args){ Scanner kbd = new Scanner(System.in); int numOfTests = Integer.parseInt(kbd.nextLine()); String[] results = new String[numOfTests]; boolean confirmed = false; String decision = ""; for(int i = 0; i < numOfTests; i++){ confirmed = false; decision = ""; double angle = Integer.parseInt(kbd.nextLine()); do{ if(angle == 60){ confirmed = true; decision = "YES"; }else if(angle < 60){ confirmed = true; decision = "NO"; }else{ double counterAngle = 180; int numOfSides = 3; do{ if((counterAngle/numOfSides) == angle){ confirmed = true; decision = "YES"; } counterAngle += 180; numOfSides++; }while((counterAngle/numOfSides) <= angle); if(confirmed == false){ confirmed = true; decision = "NO"; } } }while(confirmed == false); results[i] = decision; } for(int i = 0; i < numOfTests; i++){ System.out.println(results[i]); } } }
Java
["3\n30\n60\n90"]
2 seconds
["NO\nYES\nYES"]
NoteIn the first test case, it is impossible to build the fence, since there is no regular polygon with angle .In the second test case, the fence is a regular triangle, and in the last test case — a square.
Java 8
standard input
[ "implementation", "geometry", "math" ]
9037f487a426ead347baa803955b2c00
The first line of input contains an integer t (0 &lt; t &lt; 180) — the number of tests. Each of the following t lines contains a single integer a (0 &lt; a &lt; 180) — the angle the robot can make corners at measured in degrees.
1,100
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
standard output
PASSED
ed16471c6d8498890ba2c076a52cd046
train_000.jsonl
1359732600
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle a.Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to a?
256 megabytes
import java.util.Scanner; public class Fancy_Fence_270A { public static void main(String[] args) { Scanner tau=new Scanner(System.in); int t=tau.nextInt(); float a[]; int i; float n; a=new float[180]; for (i=0; i<t;i++) { a[i]=tau.nextInt(); } for (i=0; i<t;i++) { if (a[i]==180) System.out.println("NO"); else { n=360/(180-a[i]); if( n>=3 && Math.round(n)==n) System.out.println("YES"); else System.out.println("NO"); } } } }
Java
["3\n30\n60\n90"]
2 seconds
["NO\nYES\nYES"]
NoteIn the first test case, it is impossible to build the fence, since there is no regular polygon with angle .In the second test case, the fence is a regular triangle, and in the last test case — a square.
Java 8
standard input
[ "implementation", "geometry", "math" ]
9037f487a426ead347baa803955b2c00
The first line of input contains an integer t (0 &lt; t &lt; 180) — the number of tests. Each of the following t lines contains a single integer a (0 &lt; a &lt; 180) — the angle the robot can make corners at measured in degrees.
1,100
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
standard output
PASSED
bb760d57cc60efac222e392e7143240c
train_000.jsonl
1359732600
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle a.Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to a?
256 megabytes
import java.io.*; import java.math.*; import java.util.*; public class A { FastScanner in; PrintWriter out; void solve() { int t = in.nextInt(); while (0 < t--) { int a = in.nextInt(); String r = "NO"; for (int i = 1; i <= 360; i++) { if (i * a == ((i - 2) * 180)) { r = "YES"; break; } } out.println(r); } } void run() { try { in = new FastScanner(new File("A.in")); out = new PrintWriter(new File("A.out")); solve(); out.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } } void runIO() { in = new FastScanner(System.in); out = new PrintWriter(System.out); solve(); out.close(); } class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(File f) { try { br = new BufferedReader(new FileReader(f)); } catch (FileNotFoundException e) { e.printStackTrace(); } } public FastScanner(InputStream f) { br = new BufferedReader(new InputStreamReader(f)); } String next() { while (st == null || !st.hasMoreTokens()) { String s = null; try { s = br.readLine(); } catch (IOException e) { e.printStackTrace(); } if (s == null) return null; st = new StringTokenizer(s); } return st.nextToken(); } boolean hasMoreTokens() { while (st == null || !st.hasMoreTokens()) { String s = null; try { s = br.readLine(); } catch (IOException e) { e.printStackTrace(); } if (s == null) return false; st = new StringTokenizer(s); } return true; } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } BigInteger nextBigInteger() { return new BigInteger(next()); } double nextDouble() { return Double.parseDouble(next()); } } public static void main(String[] args) { new A().runIO(); } }
Java
["3\n30\n60\n90"]
2 seconds
["NO\nYES\nYES"]
NoteIn the first test case, it is impossible to build the fence, since there is no regular polygon with angle .In the second test case, the fence is a regular triangle, and in the last test case — a square.
Java 8
standard input
[ "implementation", "geometry", "math" ]
9037f487a426ead347baa803955b2c00
The first line of input contains an integer t (0 &lt; t &lt; 180) — the number of tests. Each of the following t lines contains a single integer a (0 &lt; a &lt; 180) — the angle the robot can make corners at measured in degrees.
1,100
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
standard output
PASSED
0340a30401f21b7e46cb1f390cee1150
train_000.jsonl
1359732600
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle a.Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to a?
256 megabytes
import java.util.Scanner; public class FancyFence { static int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for (int i = 0; i < n; i++) { System.out.println((360 % (180-sc.nextInt()) == 0) ? "YES" : "NO"); } } }
Java
["3\n30\n60\n90"]
2 seconds
["NO\nYES\nYES"]
NoteIn the first test case, it is impossible to build the fence, since there is no regular polygon with angle .In the second test case, the fence is a regular triangle, and in the last test case — a square.
Java 8
standard input
[ "implementation", "geometry", "math" ]
9037f487a426ead347baa803955b2c00
The first line of input contains an integer t (0 &lt; t &lt; 180) — the number of tests. Each of the following t lines contains a single integer a (0 &lt; a &lt; 180) — the angle the robot can make corners at measured in degrees.
1,100
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
standard output
PASSED
dcda54910e79affb3f008acf7c80dec4
train_000.jsonl
1359732600
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle a.Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to a?
256 megabytes
import java.util.HashMap; import java.util.Scanner; public class A165 { public static void main(String[] args) { Scanner in = new Scanner(System.in); //int t = in.nextInt(); float n = 3; HashMap<Integer,Boolean> map = new HashMap<>(); for(int i=0;i<=180;i++){ map.put(i,false); } for(int i=0;i<1000;i++){ float a = ((n-2)*180)/n; n++; int val = (int)a; if((a-val)==0){ map.remove(val); map.put(val,true); } //System.out.println(n+" "+a); } int t = in.nextInt(); while (t-->0){ int x = in.nextInt(); boolean ans = map.get(x); if(ans){ System.out.println("YES"); } else { System.out.println("NO"); } } //System.out.println(angle); } }
Java
["3\n30\n60\n90"]
2 seconds
["NO\nYES\nYES"]
NoteIn the first test case, it is impossible to build the fence, since there is no regular polygon with angle .In the second test case, the fence is a regular triangle, and in the last test case — a square.
Java 8
standard input
[ "implementation", "geometry", "math" ]
9037f487a426ead347baa803955b2c00
The first line of input contains an integer t (0 &lt; t &lt; 180) — the number of tests. Each of the following t lines contains a single integer a (0 &lt; a &lt; 180) — the angle the robot can make corners at measured in degrees.
1,100
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
standard output
PASSED
7ee2769b3c8fb5d221505bc1da79c1bd
train_000.jsonl
1368968400
Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4.Vasya has a set of k distinct non-negative integers d1, d2, ..., dk.Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner?
256 megabytes
import java.io.*; import java.util.*; public class StrangeAddition { static StringTokenizer st; static BufferedReader in; static PrintWriter out; private static int nextInt() throws IOException { return Integer.parseInt(next()); } private static long nextLong() throws IOException { return Long.parseLong(next()); } private static byte nextByte() throws IOException { return Byte.parseByte(next()); } private static String next() throws IOException { while(st == null || ! st.hasMoreTokens()) { st = new StringTokenizer(in.readLine()); } return st.nextToken(); } public static void main(String[] args) throws IOException { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); byte k=nextByte(); ArrayList<Byte> l=new ArrayList<>(); byte A[]=new byte[k]; byte min=110; boolean one=true; boolean tow=true; boolean three=true; byte z=0; for (int i = 0; i < k; i++) { A[i]=nextByte(); if (A[i]==0&&one) { l.add(A[i]); one=false; z++; } else if (A[i]==100&&three) { l.add(A[i]); three=false; } else if (A[i]%10==0&&tow) { l.add(A[i]); tow=false; } if (min>A[i]&&A[i]%10!=0) { min=A[i]; } } Collections.sort(l); String n=min+""; for (int i = 0; i < l.size(); i++) { if (n.length()==2) { if (l.get(i)==100||l.get(i)==0) { if (l.size()==3) { l.remove(1); } l.add(min); break; } } else if (n.length()==1) { if (l.get(i)%10==0) { l.add(min); break; } } } if(!l.isEmpty()) { System.out.println(l.size()); for (int i = 0; i < l.size(); i++) { System.out.print(l.get(i)+" "); } } else { System.out.println(1); System.out.println(min); } } }
Java
["4\n100 10 1 0", "3\n2 70 3"]
2 seconds
["4\n0 1 10 100", "2\n2 70"]
null
Java 8
standard input
[ "constructive algorithms", "implementation", "brute force" ]
6b7d6f5c07b313c57d52db6a48d3eeef
The first input line contains integer k (1 ≤ k ≤ 100) — the number of integers. The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≤ di ≤ 100).
1,600
In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers — the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order.
standard output
PASSED
dc4cf0d9e268fefe3e9b65af82249f81
train_000.jsonl
1368968400
Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4.Vasya has a set of k distinct non-negative integers d1, d2, ..., dk.Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner?
256 megabytes
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int a,b,c,d,e,f,g; a = sc.nextInt(); Vector<Integer> x = new Vector<Integer>(); g = 0; e = 0; f = 0; d = 0; for(b = 0;b < a;b++){ c = sc.nextInt(); if(c == 0){ x.add(c); } if(c == 100){ x.add(c); } if(c >= 1 && c<= 9){ if(d == 0){ d++; x.add(c); } } if(c >= 10 && c <= 99){ if(c % 10 == 0){ if(e == 0){ e++; x.add(c); } } else{ if(d == 0 && f == 0 && e == 0){ f++; x.add(c); g = x.size(); } } } } if(e >= 1 && f >= 1){ x.remove(g-1); f--; } else if(d >= 1 && f >= 1){ x.remove(g-1); } System.out.println(x.size()); for(b = 0;b < x.size();b++){ System.out.print(x.get(b)+" "); } System.out.println(); } }
Java
["4\n100 10 1 0", "3\n2 70 3"]
2 seconds
["4\n0 1 10 100", "2\n2 70"]
null
Java 8
standard input
[ "constructive algorithms", "implementation", "brute force" ]
6b7d6f5c07b313c57d52db6a48d3eeef
The first input line contains integer k (1 ≤ k ≤ 100) — the number of integers. The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≤ di ≤ 100).
1,600
In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers — the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order.
standard output
PASSED
5e14cdc35940624ff0f0488ee0997f9f
train_000.jsonl
1368968400
Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4.Vasya has a set of k distinct non-negative integers d1, d2, ..., dk.Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner?
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner s = new Scanner (System.in); boolean zero=false,one=false,ten=false,hund=false; int n=s.nextInt(); int val[] = new int [n]; int ans=0; int val2=-1; ArrayList<Integer> E= new ArrayList<Integer>(); for (int i=0;i<n;i++) { val[i]=s.nextInt(); if (ans==4) break; if (!hund && val[i]==100) { E.add(100); ans++; continue; } if (!zero && val[i]==0) { zero=true; ans++; E.add(0); continue; } if (!one && val[i]>0 && val[i]<=9) { E.add(val[i]); ans++; one=true; continue; } if (!ten && val[i]%10==0) { E.add(val[i]); ans++; ten=true; continue; } val2=val[i]; } if (!one && !ten && val2!=-1) { ans++; E.add(val2); } System.out.println(ans); for (int i=0;i<ans;i++) { System.out.print(E.get(i)+" "); } } }
Java
["4\n100 10 1 0", "3\n2 70 3"]
2 seconds
["4\n0 1 10 100", "2\n2 70"]
null
Java 8
standard input
[ "constructive algorithms", "implementation", "brute force" ]
6b7d6f5c07b313c57d52db6a48d3eeef
The first input line contains integer k (1 ≤ k ≤ 100) — the number of integers. The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≤ di ≤ 100).
1,600
In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers — the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order.
standard output
PASSED
954b49ace3da3427555326611322ff7c
train_000.jsonl
1368968400
Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4.Vasya has a set of k distinct non-negative integers d1, d2, ..., dk.Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner?
256 megabytes
import java.io.*; import java.util.*; public class A { public static void solution(BufferedReader reader, PrintWriter out) throws IOException { In in = new In(reader); int k = in.nextInt(); int n100 = -1, n10 = -1, n1 = -1, n0 = -1, n11 = -1; for (int i = 0; i < k; i++) { int d = in.nextInt(); if (n100 == -1 && d == 100) n100 = 100; else if (n10 == -1 && d >= 10 && d < 100 && d % 10 == 0) n10 = d; else if (n1 == -1 && d > 0 && d < 10) n1 = d; else if (n0 == -1 && d == 0) n0 = d; else if (n11 == -1 && d > 10 && d % 10 != 0) n11 = d; } ArrayList<Integer> ans = new ArrayList<Integer>(); if (n100 != -1) ans.add(n100); if (n10 != -1) ans.add(n10); if (n1 != -1) ans.add(n1); if (n0 != -1) ans.add(n0); if (n11 != -1 && (n10 == -1 && n1 == -1)) ans.add(n11); out.println(ans.size()); for (Integer a : ans) out.printf("%d ", a); out.println(); } public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader( System.in)); PrintWriter out = new PrintWriter(new BufferedWriter( new OutputStreamWriter(System.out))); solution(reader, out); out.close(); } protected static class In { private BufferedReader reader; private StringTokenizer tokenizer = new StringTokenizer(""); public In(BufferedReader reader) { this.reader = reader; } public String next() throws IOException { while (!tokenizer.hasMoreTokens()) tokenizer = new StringTokenizer(reader.readLine()); return tokenizer.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } } }
Java
["4\n100 10 1 0", "3\n2 70 3"]
2 seconds
["4\n0 1 10 100", "2\n2 70"]
null
Java 8
standard input
[ "constructive algorithms", "implementation", "brute force" ]
6b7d6f5c07b313c57d52db6a48d3eeef
The first input line contains integer k (1 ≤ k ≤ 100) — the number of integers. The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≤ di ≤ 100).
1,600
In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers — the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order.
standard output
PASSED
05e5ec3b796cd524bcdf9121b6284356
train_000.jsonl
1368968400
Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4.Vasya has a set of k distinct non-negative integers d1, d2, ..., dk.Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner?
256 megabytes
import java.io.*; import java.util.*; public class Test { static BufferedReader reader; static StringTokenizer tokenizer; static PrintWriter writer; static int nextInt() throws IOException { return Integer.parseInt(nextToken()); } static long nextLong() throws IOException { return Long.parseLong(nextToken()); } static double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } static String nextToken() throws IOException { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } return tokenizer.nextToken(); } static String nexts() throws IOException { tokenizer = new StringTokenizer(reader.readLine()); String s=""; while (tokenizer.hasMoreTokens()) { s+=tokenizer.nextElement()+" "; } return s; } //String str=nextToken(); //String[] s = str.split("\\s+"); public static int gcd(int x, int y){ if (y == 0) return x; else return gcd(y, x % y); } public static boolean isPrime(int n) { // Corner cases if (n <= 1){ return false; } if (n <= 3){ return true; } // This is checked so that we can skip // middle five numbers in below loop if (n % 2 == 0 || n % 3 == 0){ return false; } for (int i = 5; i * i <= n; i = i + 6) { //Checking 6i+1 & 6i-1 if (n % i == 0 || n % (i + 2) == 0) { return false; } } //O(sqrt(n)) return true; } static class R implements Comparable<R>{ int x, y; public R(int x, int y) { this.x = x; this.y = y; } public int compareTo(R o) { return x-o.x; //Increasing order(Which is usually required) } } public static void main(String[] args) throws IOException { reader = new BufferedReader(new InputStreamReader(System.in)); tokenizer = null; writer = new PrintWriter(System.out); solve(); reader.close(); writer.close(); } private static void solve() throws IOException { int k = nextInt(); int[] a=new int[k]; for(int i=0;i<k;i++){ a[i]=nextInt(); } ArrayList<Integer> arr=new ArrayList<Integer>(); int a1=-1; int a2=0; int a3=0; int a4=0; int a5=0; for(int i=0;i<k;i++){ if(a[i]==0){ arr.add(0); break; } /* else if(a[i]==100){ a2=100; } else if(a[i]%10==0){ a3=a[i]; } else if(a[i]<10){ a4=a[i]; } else{ a5=a[i]; break; }*/ } for(int i=0;i<k;i++){ if(a[i]==100){ arr.add(100); break; } } int c=1; for(int i=0;i<k;i++){ if(a[i]!=100&&a[i]!=0&&a[i]%10==0){ arr.add(a[i]); c=0; break; } } for(int i=0;i<k;i++){ if(a[i]>0&&a[i]<10){ arr.add(a[i]); c=0; break; } } if(c==1){ for(int i=0;i<k;i++){ if(a[i]>0&&a[i]<100){ arr.add(a[i]); break; } } } writer.println(arr.size()); for(int i:arr){ writer.print(i+" "); } } }
Java
["4\n100 10 1 0", "3\n2 70 3"]
2 seconds
["4\n0 1 10 100", "2\n2 70"]
null
Java 8
standard input
[ "constructive algorithms", "implementation", "brute force" ]
6b7d6f5c07b313c57d52db6a48d3eeef
The first input line contains integer k (1 ≤ k ≤ 100) — the number of integers. The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≤ di ≤ 100).
1,600
In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers — the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order.
standard output
PASSED
41bb4d02b985507d665f74908494c363
train_000.jsonl
1368968400
Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4.Vasya has a set of k distinct non-negative integers d1, d2, ..., dk.Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner?
256 megabytes
//package Omar; import java.util.Scanner; import java.util.Vector; public class StrangeAddition { public static void main(String... args) { Scanner input = new Scanner(System.in); int n = input.nextInt(); int numbers[] = new int[n]; for (int i = 0; i < n; ++i) { numbers[i] = input.nextInt(); } Vector<Integer> result = new Vector<Integer>(); boolean foundTens = false; boolean foundOnes = false; for (int i = 0; i < n; ++i) { if (!foundTens && 10 <= numbers[i] && numbers[i] < 100 && numbers[i] % 10 == 0) { result.add(numbers[i]); foundTens = true; } if (!foundOnes && 1 <= numbers[i] && numbers[i] < 10) { result.add(numbers[i]); foundOnes = true; } if (numbers[i] == 0 || numbers[i] == 100) { result.add(numbers[i]); } } for (int i = 0; i < n; ++i) { if (!foundOnes && !foundTens && 10 < numbers[i] && numbers[i] < 100) { result.add(numbers[i]); break; } } System.out.println(result.size()); for (Integer aResult : result) System.out.print(aResult + " "); } }
Java
["4\n100 10 1 0", "3\n2 70 3"]
2 seconds
["4\n0 1 10 100", "2\n2 70"]
null
Java 8
standard input
[ "constructive algorithms", "implementation", "brute force" ]
6b7d6f5c07b313c57d52db6a48d3eeef
The first input line contains integer k (1 ≤ k ≤ 100) — the number of integers. The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≤ di ≤ 100).
1,600
In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers — the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order.
standard output
PASSED
73157a144b347114d245db96c75c5c80
train_000.jsonl
1368968400
Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4.Vasya has a set of k distinct non-negative integers d1, d2, ..., dk.Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner?
256 megabytes
import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class strangeAddition { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); List<String> in=new ArrayList<>(); List<String> l=new ArrayList<>(); int[] out=new int [5]; while(n-->0){ String s=sc.next(); in.add(s); } for(int i=0;i<in.size();i++){ if(in.get(i).equalsIgnoreCase("0")){ out[0]=1; continue; } if(in.get(i).equalsIgnoreCase("100")){ out[1]=1; continue; } if(Integer.parseInt(in.get(i))%10==0){ out[2]=Integer.parseInt(in.get(i)); continue; } if(Integer.parseInt(in.get(i))<10){ out[3]=Integer.parseInt(in.get(i)); continue; } out[4]=Integer.parseInt(in.get(i)); } if(out[0]==1){ l.add("0"); } if(out[1]==1){ l.add("100"); } if(out[2]!=0){ l.add(String.valueOf(out[2])); } if(out[3]!=0){ l.add(String.valueOf(out[3])); } if(out[2]==0 && out[3]==0 && out[4]!=0){ l.add(String.valueOf(out[4])); } System.out.println(l.size()); for(int i=0;i<l.size();i++){ System.out.print(l.get(i)+" "); } } }
Java
["4\n100 10 1 0", "3\n2 70 3"]
2 seconds
["4\n0 1 10 100", "2\n2 70"]
null
Java 8
standard input
[ "constructive algorithms", "implementation", "brute force" ]
6b7d6f5c07b313c57d52db6a48d3eeef
The first input line contains integer k (1 ≤ k ≤ 100) — the number of integers. The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≤ di ≤ 100).
1,600
In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers — the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order.
standard output
PASSED
36c8705284060232dbff3d91ba7880da
train_000.jsonl
1347291900
The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement. UCDHP stores some secret information about meteors as an n × m table with integers in its cells. The order of meteors in the Universe is changing. That's why the main UCDHP module receives the following queries: The query to swap two table rows; The query to swap two table columns; The query to obtain a secret number in a particular table cell. As the main UCDHP module is critical, writing the functional of working with the table has been commissioned to you.
256 megabytes
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.HashMap; import java.util.StringTokenizer; public class Main { public static void main(String[] args) { InputReader in = new InputReader(System.in); PrintWriter out = new PrintWriter(System.out); int n = in.nextInt(); int m = in.nextInt(); int k = in.nextInt(); int[][] table = new int[n][m]; HashMap<Integer, Integer> cols = new HashMap<>(); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { table[i][j] = in.nextInt(); } } for (int i = 0; i < k; i++) { char c = in.next().charAt(0); int x = in.nextInt(); int y = in.nextInt(); if (c == 'r') { int[] temp = table[x - 1]; table[x - 1] = table[y - 1]; table[y - 1] = temp; } else if (c == 'c') { int y1 = cols.getOrDefault(y - 1, y - 1); int x1 = cols.getOrDefault(x - 1, x - 1); cols.put(x - 1, y1); cols.put(y - 1, x1); } else { out.println(table[x - 1][cols.getOrDefault(y - 1, y - 1)]); } } out.close(); } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } } }
Java
["3 3 5\n1 2 3\n4 5 6\n7 8 9\ng 3 2\nr 3 2\nc 2 3\ng 2 2\ng 3 2", "2 3 3\n1 2 4\n3 1 5\nc 2 1\nr 1 2\ng 1 3"]
3 seconds
["8\n9\n6", "5"]
NoteLet's see how the table changes in the second test case.After the first operation is fulfilled, the table looks like that:2 1 41 3 5After the second operation is fulfilled, the table looks like that:1 3 52 1 4So the answer to the third query (the number located in the first row and in the third column) will be 5.
Java 11
standard input
[ "data structures", "implementation" ]
290d9779a6be44ce6a2e62989aee0dbd
The first line contains three space-separated integers n, m and k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 500000) — the number of table columns and rows and the number of queries, correspondingly. Next n lines contain m space-separated numbers each — the initial state of the table. Each number p in the table is an integer and satisfies the inequality 0 ≤ p ≤ 106. Next k lines contain queries in the format "si xi yi", where si is one of the characters "с", "r" or "g", and xi, yi are two integers. If si = "c", then the current query is the query to swap columns with indexes xi and yi (1 ≤ x, y ≤ m, x ≠ y); If si = "r", then the current query is the query to swap rows with indexes xi and yi (1 ≤ x, y ≤ n, x ≠ y); If si = "g", then the current query is the query to obtain the number that located in the xi-th row and in the yi-th column (1 ≤ x ≤ n, 1 ≤ y ≤ m). The table rows are considered to be indexed from top to bottom from 1 to n, and the table columns — from left to right from 1 to m.
1,300
For each query to obtain a number (si = "g") print the required number. Print the answers to the queries in the order of the queries in the input.
standard output
PASSED
06708807b63c99c75220b30ae0e47604
train_000.jsonl
1347291900
The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement. UCDHP stores some secret information about meteors as an n × m table with integers in its cells. The order of meteors in the Universe is changing. That's why the main UCDHP module receives the following queries: The query to swap two table rows; The query to swap two table columns; The query to obtain a secret number in a particular table cell. As the main UCDHP module is critical, writing the functional of working with the table has been commissioned to you.
256 megabytes
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.StringTokenizer; /** * * @author LENOVO Y520 */ public class cosmictables { /** * @param args the command line arguments * @throws java.io.IOException */ public static void main(String[] args) throws IOException { // TODO code application logic here BufferedWriter out=new BufferedWriter(new OutputStreamWriter(System.out)); BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer tk=new StringTokenizer(in.readLine()); int row=Integer.parseInt(tk.nextToken()); int col=Integer.parseInt(tk.nextToken()); int x=Integer.parseInt(tk.nextToken()); int a[][]=new int[row][col]; for (int i = 0; i < row; i++) { tk=new StringTokenizer(in.readLine()); for (int j = 0; j < col; j++) { a[i][j]=Integer.parseInt(tk.nextToken()); } } int arcol[]=new int[col]; int arrow[]=new int[row]; for (int i = 0; i < col; i++) { arcol[i]=i; } for (int i = 0; i < row; i++) { arrow[i]=i; } for (int i = 0; i < x; i++) { tk=new StringTokenizer(in.readLine()); char ch=tk.nextToken().charAt(0); int num1=Integer.parseInt(tk.nextToken())-1; int num2=Integer.parseInt(tk.nextToken())-1; switch(ch){ case 'c': arcol[num1]=arcol[num1]+arcol[num2]; arcol[num2]=arcol[num1]-arcol[num2]; arcol[num1]=arcol[num1]-arcol[num2]; break; case 'r': arrow[num1]=arrow[num1]+arrow[num2]; arrow[num2]=arrow[num1]-arrow[num2]; arrow[num1]=arrow[num1]-arrow[num2]; break; case 'g': out.write(a[arrow[num1]][arcol[num2]]+" "); out.newLine(); } } out.flush(); } }
Java
["3 3 5\n1 2 3\n4 5 6\n7 8 9\ng 3 2\nr 3 2\nc 2 3\ng 2 2\ng 3 2", "2 3 3\n1 2 4\n3 1 5\nc 2 1\nr 1 2\ng 1 3"]
3 seconds
["8\n9\n6", "5"]
NoteLet's see how the table changes in the second test case.After the first operation is fulfilled, the table looks like that:2 1 41 3 5After the second operation is fulfilled, the table looks like that:1 3 52 1 4So the answer to the third query (the number located in the first row and in the third column) will be 5.
Java 11
standard input
[ "data structures", "implementation" ]
290d9779a6be44ce6a2e62989aee0dbd
The first line contains three space-separated integers n, m and k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 500000) — the number of table columns and rows and the number of queries, correspondingly. Next n lines contain m space-separated numbers each — the initial state of the table. Each number p in the table is an integer and satisfies the inequality 0 ≤ p ≤ 106. Next k lines contain queries in the format "si xi yi", where si is one of the characters "с", "r" or "g", and xi, yi are two integers. If si = "c", then the current query is the query to swap columns with indexes xi and yi (1 ≤ x, y ≤ m, x ≠ y); If si = "r", then the current query is the query to swap rows with indexes xi and yi (1 ≤ x, y ≤ n, x ≠ y); If si = "g", then the current query is the query to obtain the number that located in the xi-th row and in the yi-th column (1 ≤ x ≤ n, 1 ≤ y ≤ m). The table rows are considered to be indexed from top to bottom from 1 to n, and the table columns — from left to right from 1 to m.
1,300
For each query to obtain a number (si = "g") print the required number. Print the answers to the queries in the order of the queries in the input.
standard output
PASSED
8c395f195fec39ae1be6b3a322f5968e
train_000.jsonl
1347291900
The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement. UCDHP stores some secret information about meteors as an n × m table with integers in its cells. The order of meteors in the Universe is changing. That's why the main UCDHP module receives the following queries: The query to swap two table rows; The query to swap two table columns; The query to obtain a secret number in a particular table cell. As the main UCDHP module is critical, writing the functional of working with the table has been commissioned to you.
256 megabytes
import java.util.*; import java.io.*; import java.math.*; /* javac Main.java java Main <input.txt> output.txt */ public class Main { public static void process()throws IOException { int n=ni(); int m=ni(); int k=ni(); long arr[][]=new long[n][m]; int r[]=new int[n]; int c[]=new int[m]; for(int i=0;i<n;i++) r[i]=i; for(int i=0;i<m;i++) c[i]=i; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) arr[i][j]=nl(); } while(k-->0) { char s=nn().charAt(0); int x=ni(),y=ni(); if(s=='g') pn(arr[r[x-1]][c[y-1]]); else if(s=='c')//column swap { x-=1; y-=1; int temp=c[x]; c[x]=c[y]; c[y]=temp; } else { x-=1; y-=1; int temp=r[x]; r[x]=r[y]; r[y]=temp; } } } static AnotherReader sc; static PrintWriter out; public static void main(String[]args)throws IOException { out = new PrintWriter(System.out); sc=new AnotherReader(); boolean oj = true; //PrintWriter out=new PrintWriter("output"); //oj = System.getProperty("ONLINE_JUDGE") != null; //if(!oj) sc=new AnotherReader(100); //int i=1; // int T=ni(); // while(T-->0) process(); //{ //p("Case #"+i+": "); //i++; //} long s = System.currentTimeMillis(); out.flush(); if(!oj) System.out.println(System.currentTimeMillis()-s+"ms"); System.out.close(); } static void sort(long arr[],int n) { shuffle(arr,n); Arrays.sort(arr); } static void shuffle(long arr[],int n) { Random r=new Random(); for(int i=0;i<n;i++) { long temp=arr[i]; int pos=i+r.nextInt(n-i); arr[i]=arr[pos]; arr[pos]=temp; } } static void pn(Object o){out.println(o);} static void p(Object o){out.print(o);} static void pni(Object o){out.println(o);System.out.flush();} static int ni()throws IOException{return sc.nextInt();} static long nl()throws IOException{return sc.nextLong();} static double nd()throws IOException{return sc.nextDouble();} static String nln()throws IOException{return sc.nextLine();} static String nn()throws IOException{return sc.next();} static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);} static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);} static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));} static int[] iarr(int N)throws IOException{int[]ARR=new int[N];for(int i=0;i<N;i++){ARR[i]=ni();}return ARR;} static long[] larr(int N)throws IOException{long[]ARR=new long[N];for(int i=0;i<N;i++){ARR[i]=nl();}return ARR;} static boolean multipleTC=false; ///////////////////////////////////////////////////////////////////////////////////////////////////////// static class AnotherReader{BufferedReader br; StringTokenizer st; AnotherReader()throws FileNotFoundException{ br=new BufferedReader(new InputStreamReader(System.in));} AnotherReader(int a)throws FileNotFoundException{ br = new BufferedReader(new FileReader("input.txt"));} String next()throws IOException{ while (st == null || !st.hasMoreElements()) {try{ st = new StringTokenizer(br.readLine());} catch (IOException e){ e.printStackTrace(); }} return st.nextToken(); } int nextInt() throws IOException{ return Integer.parseInt(next());} long nextLong() throws IOException {return Long.parseLong(next());} double nextDouble()throws IOException { return Double.parseDouble(next()); } String nextLine() throws IOException{ String str = ""; try{ str = br.readLine();} catch (IOException e){ e.printStackTrace();} return str;}} ///////////////////////////////////////////////////////////////////////////////////////////////////////////// }
Java
["3 3 5\n1 2 3\n4 5 6\n7 8 9\ng 3 2\nr 3 2\nc 2 3\ng 2 2\ng 3 2", "2 3 3\n1 2 4\n3 1 5\nc 2 1\nr 1 2\ng 1 3"]
3 seconds
["8\n9\n6", "5"]
NoteLet's see how the table changes in the second test case.After the first operation is fulfilled, the table looks like that:2 1 41 3 5After the second operation is fulfilled, the table looks like that:1 3 52 1 4So the answer to the third query (the number located in the first row and in the third column) will be 5.
Java 11
standard input
[ "data structures", "implementation" ]
290d9779a6be44ce6a2e62989aee0dbd
The first line contains three space-separated integers n, m and k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 500000) — the number of table columns and rows and the number of queries, correspondingly. Next n lines contain m space-separated numbers each — the initial state of the table. Each number p in the table is an integer and satisfies the inequality 0 ≤ p ≤ 106. Next k lines contain queries in the format "si xi yi", where si is one of the characters "с", "r" or "g", and xi, yi are two integers. If si = "c", then the current query is the query to swap columns with indexes xi and yi (1 ≤ x, y ≤ m, x ≠ y); If si = "r", then the current query is the query to swap rows with indexes xi and yi (1 ≤ x, y ≤ n, x ≠ y); If si = "g", then the current query is the query to obtain the number that located in the xi-th row and in the yi-th column (1 ≤ x ≤ n, 1 ≤ y ≤ m). The table rows are considered to be indexed from top to bottom from 1 to n, and the table columns — from left to right from 1 to m.
1,300
For each query to obtain a number (si = "g") print the required number. Print the answers to the queries in the order of the queries in the input.
standard output
PASSED
f038fab895328c56d019026d83deefef
train_000.jsonl
1347291900
The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement. UCDHP stores some secret information about meteors as an n × m table with integers in its cells. The order of meteors in the Universe is changing. That's why the main UCDHP module receives the following queries: The query to swap two table rows; The query to swap two table columns; The query to obtain a secret number in a particular table cell. As the main UCDHP module is critical, writing the functional of working with the table has been commissioned to you.
256 megabytes
import javax.swing.*; import java.io.*; import java.math.BigInteger; import java.util.*; public class Main { static PrintWriter out = new PrintWriter(System.out); static int[] tree; static long m = 1000000007; public static void main(String[] args) throws IOException { //BufferedReader reader=new BufferedReader(new FileReader("input.txt")); //PrintWriter pw=new PrintWriter(new BufferedWriter(new FileWriter("output.txt"))); BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); //Scanner sc=new Scanner(System.in); //Reader sc = new Reader(); String[] s=reader.readLine().split(" "); int n=Integer.parseInt(s[0]),m=Integer.parseInt(s[1]),k=Integer.parseInt(s[2]); int[][] a=new int[n+1][m+1]; for (int i = 1; i <=n ; i++) { s=reader.readLine().split(" "); for (int j = 0; j <m ; j++) { a[i][j+1]=Integer.parseInt(s[j]); } } int[] r=new int[n+1]; int[] c=new int[m+1]; for (int i = 1; i <=n ; i++) { r[i]=i; } for (int i = 1; i <=m ; i++) { c[i]=i; } for (int i = 0; i <k; i++) { s=reader.readLine().split(" "); char h=s[0].charAt(0); int x=Integer.parseInt(s[1]),y=Integer.parseInt(s[2]); if (h=='r'){ int t=r[x]; r[x]=r[y]; r[y]=t; } else if (h=='c'){ int t=c[x]; c[x]=c[y]; c[y]=t; } else { out.println(a[r[x]][c[y]]); } } out.close(); } } class node implements Comparable<node> { Integer no; Integer cost; Vector<node> adj = new Vector<>(); public node(Integer no, Integer cost) { this.no = no; this.cost = cost; } @Override public String toString() { return "node{" + "no=" + no + ", cost=" + cost + '}'; } @Override public int compareTo(node o) { return o.cost - this.cost; } } class edge implements Comparable<edge> { tuple u; Double cost; public edge(tuple u, Double cost) { this.u = u; this.cost = cost; } @Override public int compareTo(edge o) { return this.cost.compareTo(o.cost); } @Override public String toString() { return "edge{" + "u=" + u + ", cost=" + cost + '}'; } } ///* class tuple implements Comparable<tuple> { Integer a; Integer b; public tuple(Integer a, Integer b) { this.a = a; this.b = b; } @Override public int compareTo(tuple o) { return (this.a - o.a); } @Override public String toString() { return "tuple{" + "a=" + a + ", b=" + b + '}'; } } //*/ class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') while ((c = read()) >= '0' && c <= '9') ret += (c - '0') / (div *= 10); if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } }
Java
["3 3 5\n1 2 3\n4 5 6\n7 8 9\ng 3 2\nr 3 2\nc 2 3\ng 2 2\ng 3 2", "2 3 3\n1 2 4\n3 1 5\nc 2 1\nr 1 2\ng 1 3"]
3 seconds
["8\n9\n6", "5"]
NoteLet's see how the table changes in the second test case.After the first operation is fulfilled, the table looks like that:2 1 41 3 5After the second operation is fulfilled, the table looks like that:1 3 52 1 4So the answer to the third query (the number located in the first row and in the third column) will be 5.
Java 11
standard input
[ "data structures", "implementation" ]
290d9779a6be44ce6a2e62989aee0dbd
The first line contains three space-separated integers n, m and k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 500000) — the number of table columns and rows and the number of queries, correspondingly. Next n lines contain m space-separated numbers each — the initial state of the table. Each number p in the table is an integer and satisfies the inequality 0 ≤ p ≤ 106. Next k lines contain queries in the format "si xi yi", where si is one of the characters "с", "r" or "g", and xi, yi are two integers. If si = "c", then the current query is the query to swap columns with indexes xi and yi (1 ≤ x, y ≤ m, x ≠ y); If si = "r", then the current query is the query to swap rows with indexes xi and yi (1 ≤ x, y ≤ n, x ≠ y); If si = "g", then the current query is the query to obtain the number that located in the xi-th row and in the yi-th column (1 ≤ x ≤ n, 1 ≤ y ≤ m). The table rows are considered to be indexed from top to bottom from 1 to n, and the table columns — from left to right from 1 to m.
1,300
For each query to obtain a number (si = "g") print the required number. Print the answers to the queries in the order of the queries in the input.
standard output
PASSED
f1f17abccbd40c262b06b31128c50314
train_000.jsonl
1347291900
The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement. UCDHP stores some secret information about meteors as an n × m table with integers in its cells. The order of meteors in the Universe is changing. That's why the main UCDHP module receives the following queries: The query to swap two table rows; The query to swap two table columns; The query to obtain a secret number in a particular table cell. As the main UCDHP module is critical, writing the functional of working with the table has been commissioned to you.
256 megabytes
import java.awt.*; import java.io.*; import java.math.BigInteger; import java.util.*; public class TaskC { static Long[][]dp; static int n, m, ans; static StringBuilder[]s1,s2; static int[]arr; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int n = sc.nextInt(); int m = sc.nextInt(); int q = sc.nextInt(); int[][]arr = new int[n][m]; int[]row = new int[n]; int[]col = new int[m]; for (int i = 0 ; i < n ; i++) row[i] = i; for (int i = 0 ; i < m ; i++) col[i] = i; for (int i = 0 ; i < n ; i++) { for (int j = 0; j < m; j++) arr[i][j] = sc.nextInt(); // System.out.println(Arrays.toString(arr[i])); } while (q-- >0) { StringTokenizer st = new StringTokenizer(sc.nextLine()); char t = st.nextToken().charAt(0); int i = Integer.parseInt(st.nextToken()) - 1; int j = Integer.parseInt(st.nextToken()) - 1; if( t == 'c') { int tmp = col[i]; col[i] = col[j]; col[j] = tmp; }else if( t == 'r') { int tmp = row[i]; row[i] = row[j]; row[j] = tmp; }else { pw.println(arr[row[i]][col[j]]); } /* System.out.println(Arrays.toString(row)); System.out.println(Arrays.toString(col));*/ } pw.close(); } private static long gcd(long a, long b) { if( b == 0) return a; return gcd(b , a%b); } static long lcm(int a, int b) { return (a*b)/gcd(a, b); } private static int dis(int xa , int ya , int xb , int yb) { return (xa-xb)*(xa - xb) + (ya- yb)*(ya-yb); } static class Pair implements Comparable<Pair> { int x,y; public Pair(int x, int y) { this.x = x; this.y = y; } public int compareTo(Pair o) { if (y == o.y) return o.x - x; return y - o.y; } public double dis(Pair a){ return (a.x - x)*(a.x - x) + (a.y-y)*(a.y-y); } public String toString() { return x+" "+ y; } public boolean overlap(Pair a) { if((this.x >= a.x && this.x <= a.y) || (a.x >= this.x && a.x <= this.y)) return true; return false; } } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(FileReader r) { br = new BufferedReader(r); } public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return st.nextToken(); } public boolean check() { if (!st.hasMoreTokens()) return false; return true; } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public String nextLine() { try { return br.readLine(); } catch (Exception e) { throw new RuntimeException(e); } } public double nextDouble() { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public boolean ready() { try { return br.ready(); } catch (IOException e) { throw new RuntimeException(e); } } } }
Java
["3 3 5\n1 2 3\n4 5 6\n7 8 9\ng 3 2\nr 3 2\nc 2 3\ng 2 2\ng 3 2", "2 3 3\n1 2 4\n3 1 5\nc 2 1\nr 1 2\ng 1 3"]
3 seconds
["8\n9\n6", "5"]
NoteLet's see how the table changes in the second test case.After the first operation is fulfilled, the table looks like that:2 1 41 3 5After the second operation is fulfilled, the table looks like that:1 3 52 1 4So the answer to the third query (the number located in the first row and in the third column) will be 5.
Java 11
standard input
[ "data structures", "implementation" ]
290d9779a6be44ce6a2e62989aee0dbd
The first line contains three space-separated integers n, m and k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 500000) — the number of table columns and rows and the number of queries, correspondingly. Next n lines contain m space-separated numbers each — the initial state of the table. Each number p in the table is an integer and satisfies the inequality 0 ≤ p ≤ 106. Next k lines contain queries in the format "si xi yi", where si is one of the characters "с", "r" or "g", and xi, yi are two integers. If si = "c", then the current query is the query to swap columns with indexes xi and yi (1 ≤ x, y ≤ m, x ≠ y); If si = "r", then the current query is the query to swap rows with indexes xi and yi (1 ≤ x, y ≤ n, x ≠ y); If si = "g", then the current query is the query to obtain the number that located in the xi-th row and in the yi-th column (1 ≤ x ≤ n, 1 ≤ y ≤ m). The table rows are considered to be indexed from top to bottom from 1 to n, and the table columns — from left to right from 1 to m.
1,300
For each query to obtain a number (si = "g") print the required number. Print the answers to the queries in the order of the queries in the input.
standard output
PASSED
a12729f0bbe93dc35c16f56ff4fc767b
train_000.jsonl
1347291900
The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement. UCDHP stores some secret information about meteors as an n × m table with integers in its cells. The order of meteors in the Universe is changing. That's why the main UCDHP module receives the following queries: The query to swap two table rows; The query to swap two table columns; The query to obtain a secret number in a particular table cell. As the main UCDHP module is critical, writing the functional of working with the table has been commissioned to you.
256 megabytes
import java.util.*; import java.io.*; public class A2OJ { public static class FastIO { BufferedReader br; BufferedWriter bw; StringTokenizer st; public FastIO() { br = new BufferedReader(new InputStreamReader(System.in)); bw = new BufferedWriter(new OutputStreamWriter(System.out)); st = new StringTokenizer(""); } public FastIO(int x) throws IOException { br = new BufferedReader(new FileReader("input.txt")); bw = new BufferedWriter(new FileWriter("output.txt")); st = new StringTokenizer(""); } private void read() throws IOException { st = new StringTokenizer(br.readLine()); } public String ns() throws IOException { if(!st.hasMoreTokens()) read(); return st.nextToken(); } public int ni() throws IOException { return Integer.parseInt(ns()); } public long nl() throws IOException { return Long.parseLong(ns()); } public float nf() throws IOException { return Float.parseFloat(ns()); } public double nd() throws IOException { return Double.parseDouble(ns()); } public char nc() throws IOException { return ns().charAt(0); } public int[] nia(int n) throws IOException { int[] a = new int[n]; for(int i = 0; i < n; i++) a[i] = ni(); return a; } public long[] nla(int n) throws IOException { long[] a = new long[n]; for(int i = 0; i < n; i++) a[i] = nl(); return a; } public void out(String s) throws IOException { bw.write(s); } public void flush() throws IOException { bw.flush(); } } public static void main(String args[]) throws IOException { FastIO f = new FastIO(); int n = f.ni(), m = f.ni(), k = f.ni(), p[][] = new int[n][], r[] = new int[n], c[] = new int[m], i, x, y, temp; char ch; for(i = 0; i < n; i++) { r[i] = i; p[i] = f.nia(m); } for(i = 0; i < m; i++) c[i] = i; for(i = 0; i < k; i++) { ch = f.nc(); x = f.ni()-1; y = f.ni()-1; switch(ch) { case 'c': temp = c[x]; c[x] = c[y]; c[y] = temp; break; case 'r': temp = r[x]; r[x] = r[y]; r[y] = temp; break; case 'g': f.out(p[r[x]][c[y]] + "\n"); break; } } f.flush(); } }
Java
["3 3 5\n1 2 3\n4 5 6\n7 8 9\ng 3 2\nr 3 2\nc 2 3\ng 2 2\ng 3 2", "2 3 3\n1 2 4\n3 1 5\nc 2 1\nr 1 2\ng 1 3"]
3 seconds
["8\n9\n6", "5"]
NoteLet's see how the table changes in the second test case.After the first operation is fulfilled, the table looks like that:2 1 41 3 5After the second operation is fulfilled, the table looks like that:1 3 52 1 4So the answer to the third query (the number located in the first row and in the third column) will be 5.
Java 11
standard input
[ "data structures", "implementation" ]
290d9779a6be44ce6a2e62989aee0dbd
The first line contains three space-separated integers n, m and k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 500000) — the number of table columns and rows and the number of queries, correspondingly. Next n lines contain m space-separated numbers each — the initial state of the table. Each number p in the table is an integer and satisfies the inequality 0 ≤ p ≤ 106. Next k lines contain queries in the format "si xi yi", where si is one of the characters "с", "r" or "g", and xi, yi are two integers. If si = "c", then the current query is the query to swap columns with indexes xi and yi (1 ≤ x, y ≤ m, x ≠ y); If si = "r", then the current query is the query to swap rows with indexes xi and yi (1 ≤ x, y ≤ n, x ≠ y); If si = "g", then the current query is the query to obtain the number that located in the xi-th row and in the yi-th column (1 ≤ x ≤ n, 1 ≤ y ≤ m). The table rows are considered to be indexed from top to bottom from 1 to n, and the table columns — from left to right from 1 to m.
1,300
For each query to obtain a number (si = "g") print the required number. Print the answers to the queries in the order of the queries in the input.
standard output
PASSED
9a816eb6aba0fd634d7571dab7afbc0a
train_000.jsonl
1347291900
The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement. UCDHP stores some secret information about meteors as an n × m table with integers in its cells. The order of meteors in the Universe is changing. That's why the main UCDHP module receives the following queries: The query to swap two table rows; The query to swap two table columns; The query to obtain a secret number in a particular table cell. As the main UCDHP module is critical, writing the functional of working with the table has been commissioned to you.
256 megabytes
import java.io.*; import java.util.*; public class main { static StringBuilder out=new StringBuilder(); static FastReader in=new FastReader(); public static void main(String []args){ int n=in.nextInt(), m=in.nextInt(), k=in.nextInt(); int arr[][]=new int[n][m]; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ arr[i][j]=in.nextInt(); } } int []con=new int[m]; for(int i=0;i<con.length;i++){ con[i]=i; } while(k-->0){ char ch=in.next().toCharArray()[0]; switch(ch){ case ('c'): int i=in.nextInt()-1, j=in.nextInt()-1; int dd=con[i]; con[i]=con[j]; con[j]=dd; break; case ('r'): i=in.nextInt()-1; j=in.nextInt()-1; int temp[]=arr[i]; arr[i]=arr[j]; arr[j]=temp; break; default: out.append(arr[in.nextInt()-1][con[in.nextInt()-1]]).append('\n'); } } System.out.println(out); } public static int[] getIntArray(int n){ int arr[]=new int[n]; for(int i=0;i<n;i++){ arr[i]=in.nextInt(); } return arr; } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["3 3 5\n1 2 3\n4 5 6\n7 8 9\ng 3 2\nr 3 2\nc 2 3\ng 2 2\ng 3 2", "2 3 3\n1 2 4\n3 1 5\nc 2 1\nr 1 2\ng 1 3"]
3 seconds
["8\n9\n6", "5"]
NoteLet's see how the table changes in the second test case.After the first operation is fulfilled, the table looks like that:2 1 41 3 5After the second operation is fulfilled, the table looks like that:1 3 52 1 4So the answer to the third query (the number located in the first row and in the third column) will be 5.
Java 11
standard input
[ "data structures", "implementation" ]
290d9779a6be44ce6a2e62989aee0dbd
The first line contains three space-separated integers n, m and k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 500000) — the number of table columns and rows and the number of queries, correspondingly. Next n lines contain m space-separated numbers each — the initial state of the table. Each number p in the table is an integer and satisfies the inequality 0 ≤ p ≤ 106. Next k lines contain queries in the format "si xi yi", where si is one of the characters "с", "r" or "g", and xi, yi are two integers. If si = "c", then the current query is the query to swap columns with indexes xi and yi (1 ≤ x, y ≤ m, x ≠ y); If si = "r", then the current query is the query to swap rows with indexes xi and yi (1 ≤ x, y ≤ n, x ≠ y); If si = "g", then the current query is the query to obtain the number that located in the xi-th row and in the yi-th column (1 ≤ x ≤ n, 1 ≤ y ≤ m). The table rows are considered to be indexed from top to bottom from 1 to n, and the table columns — from left to right from 1 to m.
1,300
For each query to obtain a number (si = "g") print the required number. Print the answers to the queries in the order of the queries in the input.
standard output
PASSED
59f3d5afa7f7687f1ba9a909bc4c246d
train_000.jsonl
1347291900
The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement. UCDHP stores some secret information about meteors as an n × m table with integers in its cells. The order of meteors in the Universe is changing. That's why the main UCDHP module receives the following queries: The query to swap two table rows; The query to swap two table columns; The query to obtain a secret number in a particular table cell. As the main UCDHP module is critical, writing the functional of working with the table has been commissioned to you.
256 megabytes
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.StringTokenizer; public class CosmicTable { public static void main(String[] args) throws Exception { BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter ot = new BufferedWriter(new OutputStreamWriter(System.out)); StringTokenizer tok = new StringTokenizer(read.readLine()); int n = Integer.parseInt(tok.nextToken()); int m = Integer.parseInt(tok.nextToken()); int k = Integer.parseInt(tok.nextToken()); int mat [][] = new int[n][m]; for (int i = 0; i < n; i++) { tok = new StringTokenizer(read.readLine()); for (int j = 0; j < m; j++) { mat[i][j] = Integer.parseInt(tok.nextToken()); } } int [] row = new int[n]; int [] col = new int[m]; for (int i = 0; i <n; i++) { row[i] = i; } for (int i = 0; i <m; i++) { col[i] = i; } // col = [1,3,2] // row = [1,3,2] for (int i = 0; i < k; i++) { tok = new StringTokenizer(read.readLine()); char c = tok.nextToken().charAt(0); int num1 = Integer.parseInt(tok.nextToken()) - 1; int num2 = Integer.parseInt(tok.nextToken()) - 1; switch (c) { case 'c' : col[num1] = col[num1] + col[num2]; col[num2] = col[num1] - col[num2]; col[num1] = col[num1] - col[num2]; break; case 'r' : row[num1] = row[num1] + row[num2]; row[num2] = row[num1] - row[num2]; row[num1] = row[num1] - row[num2]; break; case 'g' : ot.write(mat[row[num1]][col[num2]] + ""); ot.newLine(); break; } } ot.flush(); } }
Java
["3 3 5\n1 2 3\n4 5 6\n7 8 9\ng 3 2\nr 3 2\nc 2 3\ng 2 2\ng 3 2", "2 3 3\n1 2 4\n3 1 5\nc 2 1\nr 1 2\ng 1 3"]
3 seconds
["8\n9\n6", "5"]
NoteLet's see how the table changes in the second test case.After the first operation is fulfilled, the table looks like that:2 1 41 3 5After the second operation is fulfilled, the table looks like that:1 3 52 1 4So the answer to the third query (the number located in the first row and in the third column) will be 5.
Java 11
standard input
[ "data structures", "implementation" ]
290d9779a6be44ce6a2e62989aee0dbd
The first line contains three space-separated integers n, m and k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 500000) — the number of table columns and rows and the number of queries, correspondingly. Next n lines contain m space-separated numbers each — the initial state of the table. Each number p in the table is an integer and satisfies the inequality 0 ≤ p ≤ 106. Next k lines contain queries in the format "si xi yi", where si is one of the characters "с", "r" or "g", and xi, yi are two integers. If si = "c", then the current query is the query to swap columns with indexes xi and yi (1 ≤ x, y ≤ m, x ≠ y); If si = "r", then the current query is the query to swap rows with indexes xi and yi (1 ≤ x, y ≤ n, x ≠ y); If si = "g", then the current query is the query to obtain the number that located in the xi-th row and in the yi-th column (1 ≤ x ≤ n, 1 ≤ y ≤ m). The table rows are considered to be indexed from top to bottom from 1 to n, and the table columns — from left to right from 1 to m.
1,300
For each query to obtain a number (si = "g") print the required number. Print the answers to the queries in the order of the queries in the input.
standard output
PASSED
d6f7e51948680f6441a0c782d26fd64f
train_000.jsonl
1443890700
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as . For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows: Given all the numbers of the GCD table G, restore array a.
256 megabytes
import java.io.*; import java.util.*; /** * @author master_j * @version 0.4.1 * @since Mar 22, 2015 */ public class Solution { private int gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a % b); } private void solve() throws IOException { // { // Random random = new Random(); // int n = random.nextInt(100) + 100; // int[] a = new int[n]; // for (int i = 0; i < n; i++) // a[i] = random.nextInt(13) + 1; // int[][] b = new int[n][n]; // for (int i = 0; i < n; i++) { // for (int j = 0; j < n; j++) { // b[i][j] = gcd(a[i], a[j]); // } // } // io.wln(n); // for (int[] i : b) // for (int j : i) // io.w(j + " "); // io.wln(); // io.wln(); // io.wln("Answer is :"); // io.w(Arrays.toString(a)); // } // if (1 == 1) return; int n = io.nI(); int[] a = io.nIa(n * n); Arrays.sort(a); TreeMap<Integer, Integer> count = new TreeMap<>(); for (Integer i : a) { if (!count.containsKey(i)) count.put(i, 0); count.put(i, 1 + count.get(i)); } List<Integer> ans = new ArrayList<>(n); while (count.lastEntry().getValue() > 0) ans(count, ans, count.lastKey(), false); assert count.lastEntry().getValue() == 0; count.pollLastEntry(); while (!count.isEmpty()) ans(count, ans, count.lastKey(), true); for (int i : ans) io.w(i + " "); }//2.2250738585072012e-308 private void ans(Map<Integer, Integer> count, List<Integer> ans, int x, boolean remove) { for (int i : ans) { int g = gcd(i, x); dec(count, g, remove); dec(count, g, remove); } dec(count, x, remove); ans.add(x); } private void dec(Map<Integer, Integer> count, int x, boolean remove) { count.put(x, count.get(x) - 1); if (remove && count.get(x) == 0) count.remove(x); } public static void main(String[] args) throws IOException { IO.launchSolution(args); } Solution(IO io) throws IOException { this.io = io; solve(); } private final IO io; } class IO { static final String _localArg = "master_j"; private static final String _problemName = ""; private static final IO.Mode _inMode = Mode.STD_; private static final IO.Mode _outMode = Mode.STD_; private static final boolean _autoFlush = false; enum Mode {STD_, _PUT_TXT, PROBNAME_} private final StreamTokenizer st; private final BufferedReader br; private final Reader reader; private final PrintWriter pw; private final Writer writer; static void launchSolution(String[] args) throws IOException { boolean local = (args.length == 1 && args[0].equals(IO._localArg)); IO io = new IO(local); long nanoTime = 0; if (local) { nanoTime -= System.nanoTime(); io.wln("<output>"); } io.flush(); new Solution(io); io.flush(); if (local) { io.wln("</output>"); nanoTime += System.nanoTime(); final long D9 = 1000000000, D6 = 1000000, D3 = 1000; if (nanoTime >= D9) io.wf("%d.%d seconds\n", nanoTime / D9, nanoTime % D9); else if (nanoTime >= D6) io.wf("%d.%d millis\n", nanoTime / D6, nanoTime % D6); else if (nanoTime >= D3) io.wf("%d.%d micros\n", nanoTime / D3, nanoTime % D3); else io.wf("%d nanos\n", nanoTime); } io.close(); } IO(boolean local) throws IOException { if (_inMode == Mode.PROBNAME_ || _outMode == Mode.PROBNAME_) if (_problemName.length() == 0) throw new IllegalStateException("You imbecile. Where's my <_problemName>?"); if (_problemName.length() > 0) if (_inMode != Mode.PROBNAME_ && _outMode != Mode.PROBNAME_) throw new IllegalStateException("You imbecile. What's the <_problemName> for?"); Locale.setDefault(Locale.US); if (local) { reader = new FileReader("input.txt"); writer = new OutputStreamWriter(System.out); } else { switch (_inMode) { case STD_: reader = new InputStreamReader(System.in); break; case PROBNAME_: reader = new FileReader(_problemName + ".in"); break; case _PUT_TXT: reader = new FileReader("input.txt"); break; default: throw new NullPointerException("You imbecile. Gimme _inMode."); } switch (_outMode) { case STD_: writer = new OutputStreamWriter(System.out); break; case PROBNAME_: writer = new FileWriter(_problemName + ".out"); break; case _PUT_TXT: writer = new FileWriter("output.txt"); break; default: throw new NullPointerException("You imbecile. Gimme _outMode."); } } br = new BufferedReader(reader); st = new StreamTokenizer(br); pw = new PrintWriter(writer, _autoFlush); if (local && _autoFlush) wln("Note: auto-flush is on."); } //@formatter:off void wln() {pw.println(); } void wln(boolean x) {pw.println(x);} void wln(char x) {pw.println(x);} void wln(char x[]) {pw.println(x);} void wln(double x) {pw.println(x);} void wln(float x) {pw.println(x);} void wln(int x) {pw.println(x);} void wln(long x) {pw.println(x);} void wln(Object x) {pw.println(x);} void wln(String x) {pw.println(x);} void wf(String f, Object... o) {pw.printf(f, o);} void w(boolean x) {pw.print(x);} void w(char x) {pw.print(x);} void w(char x[]) {pw.print(x);} void w(double x) {pw.print(x);} void w(float x) {pw.print(x);} void w(int x) {pw.print(x);} void w(long x) {pw.print(x);} void w(Object x) {pw.print(x);} void w(String x) {pw.print(x);} int nI() throws IOException {st.nextToken(); return (int)st.nval;} double nD() throws IOException {st.nextToken(); return st.nval;} float nF() throws IOException {st.nextToken(); return (float)st.nval;} long nL() throws IOException {st.nextToken(); return (long)st.nval;} String nS() throws IOException {st.nextToken(); return st.sval;} int[] nIa(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nI(); return a; } double[] nDa(int n) throws IOException { double[] a = new double[n]; for (int i = 0; i < n; i++) a[i] = nD(); return a; } String[] nSa(int n) throws IOException { String[] a = new String[n]; for (int i = 0; i < n; i++) a[i] = nS(); return a; } void wc(String x) {wc(x.toCharArray());} void wc(char c1, char c2) {for (char c = c1; c<=c2; c++) wc(c);} void wc(char x[]) {for (char c : x) wc(c); } void wc(char x) {st.ordinaryChar(x); st.wordChars(x, x);} public boolean eof() {return st.ttype == StreamTokenizer.TT_EOF;} public boolean eol() {return st.ttype == StreamTokenizer.TT_EOL;} void flush() {pw.flush();} void close() throws IOException {reader.close(); br.close(); flush(); pw.close();} //@formatter:on }
Java
["4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2", "1\n42", "2\n1 1 1 1"]
2 seconds
["4 3 6 2", "42", "1 1"]
null
Java 8
standard input
[ "constructive algorithms", "number theory" ]
71dc07f0ea8962f23457af1d6509aeee
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a. All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
1,700
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
standard output
PASSED
3e94df8bfdb16f0d1b858cd122df36a7
train_000.jsonl
1443890700
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as . For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows: Given all the numbers of the GCD table G, restore array a.
256 megabytes
// Problem : C. GCD Table // Contest : Codeforces - Codeforces Round #323 (Div. 2) // URL : https://codeforces.com/contest/583/problem/C // Memory Limit : 0 MB // Time Limit : 0 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) import java.io.*; import java.util.*; public class a implements Runnable{ public static void main(String[] args) { new Thread(null, new a(), "process", 1<<26).start(); } public void run() { FastReader scan = new FastReader(); PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); //PrintWriter out = new PrintWriter("file.out"); Task solver = new Task(); //int t = scan.nextInt(); int t = 1; for(int i = 1; i <= t; i++) solver.solve(i, scan, out); out.close(); } static class Task { static final int inf = Integer.MAX_VALUE; public void solve(int testNumber, FastReader sc, PrintWriter pw) { //CHECK FOR QUICKSORT TLE //***********************// //CHECK FOR INT OVERFLOW //***********************// int n = sc.nextInt(); int[] arr = new int[n * n]; for(int i = 0;i < n * n; i++){ arr[i] = sc.nextInt(); } Arrays.sort(arr); ArrayList<Integer> kep = new ArrayList<Integer>(); HashMap<Integer,Integer> need = new HashMap<>(); int ptr = n * n - 1; l: for(int i = 0;i < n; i++){ while(true){ if(ptr < 0)break l; if(need.get(arr[ptr]) == null || need.get(arr[ptr]) == 0){ for(int x : kep){ int gcd = gcd(x, arr[ptr]); need.put(gcd, need.getOrDefault(gcd, 0) + 2); } kep.add(arr[ptr]); ptr--; break; } else{ need.put(arr[ptr],need.get(arr[ptr]) - 1); } ptr--; if(ptr < 0)break l; } } for(int x : kep){ pw.print(x + " "); } pw.println(); } int gcd(int a, int b){ return b == 0 ? a : gcd(b, a % b); } } static long binpow(long a, long b, long m) { a %= m; long res = 1; while (b > 0) { if ((b & 1) == 1) res = res * a % m; a = a * a % m; b >>= 1; } return res; } static void sort(int[] x){ shuffle(x); Arrays.sort(x); } static void sort(long[] x){ shuffle(x); Arrays.sort(x); } static class tup implements Comparable<tup>{ int a, b; tup(int a,int b){ this.a=a; this.b=b; } @Override public int compareTo(tup o){ return Integer.compare(o.b,b); } } static void shuffle(int[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); int temp = a[i]; a[i] = a[r]; a[r] = temp; } } static void shuffle(long[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); long temp = a[i]; a[i] = a[r]; a[r] = temp; } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } public FastReader(String s) throws FileNotFoundException { br = new BufferedReader(new FileReader(new File(s))); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2", "1\n42", "2\n1 1 1 1"]
2 seconds
["4 3 6 2", "42", "1 1"]
null
Java 8
standard input
[ "constructive algorithms", "number theory" ]
71dc07f0ea8962f23457af1d6509aeee
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a. All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
1,700
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
standard output
PASSED
eb1e508a13f6de044b3a891497f99c92
train_000.jsonl
1443890700
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as . For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows: Given all the numbers of the GCD table G, restore array a.
256 megabytes
import java.util.Arrays; import java.util.ArrayList; import java.io.InputStream; import java.io.InputStreamReader; import java.util.HashMap; import java.io.BufferedReader; import java.util.List; import java.io.OutputStream; import java.util.Comparator; import java.io.PrintWriter; import java.io.Writer; import java.io.FileReader; import java.io.IOException; import java.util.StringTokenizer; /** * Built using CHelper plug-in * Actual solution is at the top * @author Agostinho Junior (junior94) */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); TaskC solver = new TaskC(); solver.solve(1, in, out); out.close(); } } class TaskC { public void solve(int testNumber, InputReader in, OutputWriter out) { int n = in.readInt(); Integer[] table = new Integer[n * n]; HashMap<Integer, Integer> count = new HashMap<>(); for (int i = 0; i < table.length; i++) { table[i] = in.readInt(); Integer prev = count.get(table[i]); if (prev == null) { prev = 0; } count.put(table[i], prev + 1); } Arrays.sort(table, (a, b) -> b - a); int[] a = new int[n]; int i = 0; for (int gcd: table) { Integer cur = count.get(gcd); if (cur > 0) { a[i] = gcd; out.print(a[i] + " "); count.put(a[i], cur - 1); for (int j = 0; j < i; j++) { int value = XMath.gcd(a[j], a[i]); count.put(value, count.get(value) - 2); } i++; } } out.println(); } } class InputReader { private BufferedReader input; private StringTokenizer line = new StringTokenizer(""); public InputReader(InputStream in) {input = new BufferedReader(new InputStreamReader(in)); } public void fill() { try { if(!line.hasMoreTokens()) line = new StringTokenizer(input.readLine()); } catch(IOException io) { io.printStackTrace(); System.exit(0);} } public int readInt() { fill(); return Integer.parseInt(line.nextToken()); } } class OutputWriter { private PrintWriter output; public OutputWriter(OutputStream out) { output = new PrintWriter(out); } public void print(Object o) { output.print(o); } public void println() { output.println(); } public void close() { output.close(); } } class XMath { public static int gcd(int a, int b) { int c; while (b > 0) { c = a % b; a = b; b = c; } return a; } }
Java
["4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2", "1\n42", "2\n1 1 1 1"]
2 seconds
["4 3 6 2", "42", "1 1"]
null
Java 8
standard input
[ "constructive algorithms", "number theory" ]
71dc07f0ea8962f23457af1d6509aeee
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a. All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
1,700
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
standard output
PASSED
c9e1dce37aa4e6b5bffff318cb31ac43
train_000.jsonl
1443890700
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as . For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows: Given all the numbers of the GCD table G, restore array a.
256 megabytes
import java.io.InputStream; import java.io.OutputStream; import java.io.IOException; import java.util.ArrayList; import java.io.InputStream; import java.io.BufferedReader; import java.util.List; import java.util.TreeMap; import java.io.InputStreamReader; import java.io.IOException; import java.io.PrintWriter; import java.util.StringTokenizer; import java.util.Collection; /** * Built using CHelper plug-in * Actual solution is at the top * * @author AlexFetisov */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskA_CF323 solver = new TaskA_CF323(); solver.solve(1, in, out); out.close(); } static class TaskA_CF323 { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); TreeCounter<Integer> counter = new TreeCounter<Integer>(); List<Integer> res = new ArrayList<Integer>(n); for (int i = 0; i < n * n; ++i) { counter.add(in.nextInt()); } for (int iter = 0; iter < n; ++iter) { int value = counter.last(); counter.remove(value); for (int x : res) { counter.remove(IntegerUtils.gcd(x, value)); counter.remove(IntegerUtils.gcd(x, value)); } res.add(value); } out.println(ArrayUtils.toString(res)); } } static class InputReader { private BufferedReader reader; private StringTokenizer stt; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); } public String nextLine() { try { return reader.readLine(); } catch (IOException e) { return null; } } public String nextString() { while (stt == null || !stt.hasMoreTokens()) { stt = new StringTokenizer(nextLine()); } return stt.nextToken(); } public int nextInt() { return Integer.parseInt(nextString()); } } static class ArrayUtils { public static String toString(Collection<Integer> collection) { StringBuilder result = new StringBuilder(""); for (int x : collection) { result.append(x).append(" "); } return result.substring(0, result.length() - 1); } } static class IntegerUtils { public static int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); } } static class TreeCounter<K> { private final TreeMap<K, Integer> map; long size; public TreeCounter() { map = new TreeMap<K, Integer>(); size = 0; } public int add(K key, int count) { Integer value = map.get(key); if (value == null) { value = 0; } value += count; map.put(key, value); size += count; return value; } public int add(K key) { return add(key, 1); } public int remove(K key) { Integer value = map.get(key); if (value == null) { return 0; } --value; if (value == 0) { map.remove(key); } else { map.put(key, value); } --size; return value; } public K last() { return map.lastKey(); } } }
Java
["4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2", "1\n42", "2\n1 1 1 1"]
2 seconds
["4 3 6 2", "42", "1 1"]
null
Java 8
standard input
[ "constructive algorithms", "number theory" ]
71dc07f0ea8962f23457af1d6509aeee
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a. All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
1,700
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
standard output
PASSED
bd91c3506970149274b8a171f39fbd30
train_000.jsonl
1443890700
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as . For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows: Given all the numbers of the GCD table G, restore array a.
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); TaskC solver = new TaskC(); solver.solve(in, out); out.close(); } } class TaskC { private TreeMap<Integer, Integer> map; public void solve(InputReader in, OutputWriter out) { int n = in.nextInt(); map = new TreeMap<>(Comparator.<Integer>reverseOrder()); for (int i = 0; i < n*n; i++) { int val = in.nextInt(); map.put(val, (map.containsKey(val) ? map.get(val) + 1 : 1)); } int result[] = new int[n]; result[0] = decrease(); for(int i=1;i<n;i++) { result[i] = decrease(); for(int j = 0; j < i; j++) { int gcd = gcd(result[i], result[j]); map.put(gcd, map.get(gcd) - 2); if(map.get(gcd) <= 0) map.remove(gcd); } } for(int i=0;i<n;i++) { out.print(result[i] + " "); } } private int decrease() { Map.Entry<Integer, Integer> entry = map.firstEntry(); if(entry.getValue() == 1) { map.remove(entry.getKey()); } else { map.put(entry.getKey(), entry.getValue()-1); } return entry.getKey(); } private int gcd(int a, int b) { if(b == 0) return a; return gcd(b, a % b); } } class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public boolean hasNext() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { String line = reader.readLine(); if (line == null) { return false; } tokenizer = new StringTokenizer(line); } catch (IOException e) { throw new RuntimeException(e); } } return true; } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } } class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) { writer.print(' '); } writer.print(objects[i]); } } public void printLine(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } }
Java
["4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2", "1\n42", "2\n1 1 1 1"]
2 seconds
["4 3 6 2", "42", "1 1"]
null
Java 8
standard input
[ "constructive algorithms", "number theory" ]
71dc07f0ea8962f23457af1d6509aeee
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a. All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
1,700
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
standard output
PASSED
d919f722625b465ed26cd2817b461e94
train_000.jsonl
1443890700
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as . For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows: Given all the numbers of the GCD table G, restore array a.
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); TreeMap<Integer, Integer> set = new TreeMap<>(); int n = Integer.parseInt(in.readLine()); StringTokenizer st = new StringTokenizer(in.readLine()); for (int i = 0; i < n*n; i++) { int x = Integer.parseInt(st.nextToken()); if (set.containsKey(x)) { set.put(x, set.get(x)+1); } else { set.put(x, 1); } } ArrayList<Integer> chosen = new ArrayList<>(); for (int i = 0; i < n; i++) { int x = set.floorEntry((int)1e9).getKey(); //System.out.println("choose " + x); set.put(x, set.get(x)-1); if (set.get(x) == 0) { set.remove(x); } //System.out.println("remove 1 of " + x); for (int j : chosen) { int gcd = gcd(j, x); //System.out.println("remove 2 of " + gcd); set.put(gcd, set.get(gcd)-2); if (set.get(gcd) == 0) { set.remove(gcd); } } chosen.add(x); } for (int i = 0; i < n; i++) { if (i > 0) { out.print(' '); } out.print(chosen.get(i)); } out.print('\n'); out.close(); } public static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } } /* */
Java
["4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2", "1\n42", "2\n1 1 1 1"]
2 seconds
["4 3 6 2", "42", "1 1"]
null
Java 8
standard input
[ "constructive algorithms", "number theory" ]
71dc07f0ea8962f23457af1d6509aeee
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a. All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
1,700
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
standard output
PASSED
75f54f37e906280352da16ba08940c94
train_000.jsonl
1443890700
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as . For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows: Given all the numbers of the GCD table G, restore array a.
256 megabytes
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ import java.util.ArrayList; import java.util.Scanner; import java.util.TreeMap; /** * * @author Simone Vuotto */ public class C { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>(); for(int i = 0; i < n * n; ++i) { int k = scanner.nextInt(); if( map.containsKey(k)) map.put(k, map.get(k) + 1); else map.put(k, 1); } ArrayList<Integer> a = new ArrayList<Integer>(); while(a.size() != n) { int k = map.lastKey(); int occurences = map.get(k); if(occurences == 0){ map.remove(k); continue; } map.put(k, occurences -1); for(int l : a) { int g = GCD(k, l); map.put(g, map.get(g) - 2); } a.add(k); } for(int i = 0; i < n; ++i) System.out.print(a.get(i) + " "); } public static int GCD(int a, int b) { if (b==0) return a; return GCD(b,a%b); } }
Java
["4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2", "1\n42", "2\n1 1 1 1"]
2 seconds
["4 3 6 2", "42", "1 1"]
null
Java 8
standard input
[ "constructive algorithms", "number theory" ]
71dc07f0ea8962f23457af1d6509aeee
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a. All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
1,700
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
standard output
PASSED
fe6c7d5afad631709c51f303a68b1709
train_000.jsonl
1443890700
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as . For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows: Given all the numbers of the GCD table G, restore array a.
256 megabytes
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ //package codeforces323; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import static java.util.Arrays.sort; import java.util.HashMap; import java.util.Hashtable; /** * * @author Sourav Kumar Paul */ public class SolveC { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String line[] = reader.readLine().split(" "); int n = Integer.parseInt(line[0]); line = reader.readLine().split(" "); int nos[] = new int[n*n]; Hashtable<Integer, Integer> map = new Hashtable<Integer, Integer>(); // int hash[] = new int[1000000001]; for(int j=0; j<n*n; j++) { nos[j] = Integer.parseInt(line[j]); if(map.containsKey(nos[j])) map.replace(nos[j], map.get(nos[j] )+ 1); else map.put(nos[j], 1); // hash[nos[j]] ++; } sort(nos); int ans[] = new int[n]; int x; int k = n*n - 1; for(int i=0 ; i<n; i++) { while(true) { x = nos[k--]; if(map.get(x) > 0) break; } ans[i] = x; System.out.print(x+ " "); map.replace(x, map.get(x )- 1); // hash[x] --; for(int j=0; j<i; j++) { int gcd = gcd(ans[i], ans[j]); map.replace(gcd, map.get(gcd )-2); // hash[gcd] = hash[gcd] - 2; } } } private static int gcd(int a ,int b) { return b == 0 ? a : gcd(b, a % b); } }
Java
["4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2", "1\n42", "2\n1 1 1 1"]
2 seconds
["4 3 6 2", "42", "1 1"]
null
Java 8
standard input
[ "constructive algorithms", "number theory" ]
71dc07f0ea8962f23457af1d6509aeee
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a. All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
1,700
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
standard output
PASSED
fc5c4e3d26a536fb9911e75232c2da4d
train_000.jsonl
1443890700
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as . For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows: Given all the numbers of the GCD table G, restore array a.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Map.Entry; import java.util.StringTokenizer; import java.util.TreeMap; public class Main { public static void main(String args[]) throws NumberFormatException,IOException { Stdin in = new Stdin(); PrintWriter out = new PrintWriter(System.out); int n=in.readInt(); int a; TreeMap<Integer,Integer>map=new TreeMap<Integer,Integer>((a1,a2)->a2-a1); for(int i=0;i<n*n;i++){ a=in.readInt(); if(map.containsKey(a)){ map.put(a, map.get(a)+1); }else{ map.put(a, 1); } } int []num=new int[n]; int pos=0; Entry<Integer,Integer>cur; while(!map.isEmpty()){ cur=map.firstEntry(); num[pos++]=cur.getKey(); if(map.get(cur.getKey())==1){ map.remove(cur.getKey()); }else{ map.put(cur.getKey(), map.get(cur.getKey())-1); } for(int i=0;i<pos-1;i++){ int gcd=gcd(num[pos-1],num[i]); if(map.get(gcd)==2){ map.remove(gcd); }else{ map.put(gcd, map.get(gcd)-2); } } } for(int i=0;i<pos;i++){ if(i>0){ out.print(" "); } out.print(num[i]); } out.flush(); out.close(); } private static int gcd(int a,int b){ if(b==0){ return a; } return gcd(b,a%b); } private static class Stdin { InputStreamReader read; BufferedReader br; StringTokenizer st = new StringTokenizer(""); private Stdin() { read = new InputStreamReader(System.in); br = new BufferedReader(read); } private String readNext() throws IOException { while (!st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } private int readInt() throws IOException, NumberFormatException { return Integer.parseInt(readNext()); } private long readLong() throws IOException, NumberFormatException { return Long.parseLong(readNext()); } } }
Java
["4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2", "1\n42", "2\n1 1 1 1"]
2 seconds
["4 3 6 2", "42", "1 1"]
null
Java 8
standard input
[ "constructive algorithms", "number theory" ]
71dc07f0ea8962f23457af1d6509aeee
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a. All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
1,700
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
standard output
PASSED
4a70a20dac3d7dfc8e779c40cdb23411
train_000.jsonl
1443890700
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as . For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows: Given all the numbers of the GCD table G, restore array a.
256 megabytes
import java.io.*; import java.math.*; import java.util.*; import java.util.stream.*; import java.util.concurrent.*; @SuppressWarnings("unchecked") public class P583C { int gcd(int a, int b) { return ((b > 0) ? gcd(b, a % b) : a); } TreeMap<Integer, Integer> nc = new TreeMap(Comparator.reverseOrder()); void decNC(int val, int cnt) { cnt = nc.getOrDefault(val, 0) - cnt; if (cnt > 0) { nc.put(val, cnt); } else { nc.remove(val); } } public void run() throws Exception { final int n = nextInt(); List<Integer> res = new ArrayList(); for (int i = n * n; i > 0; i--) { int v = nextInt(); nc.put(v, nc.getOrDefault(v, 0) + 1); } while (!nc.isEmpty()) { Map.Entry<Integer, Integer> me = nc.firstEntry(); for (int r : res) { int gcd = gcd(me.getKey(), r); decNC(gcd, 2); } decNC(me.getKey(), 1); res.add(me.getKey()); } for (int i : res) { print(i + " "); } } public static void main(String... args) throws Exception { br = new BufferedReader(new InputStreamReader(System.in)); pw = new PrintWriter(new BufferedOutputStream(System.out)); new P583C().run(); br.close(); pw.close(); System.err.println("\n[Time : " + (System.currentTimeMillis() - startTime) + " ms]"); } static long startTime = System.currentTimeMillis(); static BufferedReader br; static PrintWriter pw; StringTokenizer stok; String nextToken() throws IOException { while (stok == null || !stok.hasMoreTokens()) { String s = br.readLine(); if (s == null) { return null; } stok = new StringTokenizer(s); } return stok.nextToken(); } void print(byte b) { print("" + b); } void print(int i) { print("" + i); } void print(long l) { print("" + l); } void print(double d) { print("" + d); } void print(char c) { print("" + c); } void print(Object o) { if (o instanceof int[]) { print(Arrays.toString((int [])o)); } else if (o instanceof long[]) { print(Arrays.toString((long [])o)); } else if (o instanceof char[]) { print(Arrays.toString((char [])o)); } else if (o instanceof byte[]) { print(Arrays.toString((byte [])o)); } else if (o instanceof short[]) { print(Arrays.toString((short [])o)); } else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o)); } else if (o instanceof float[]) { print(Arrays.toString((float [])o)); } else if (o instanceof double[]) { print(Arrays.toString((double [])o)); } else if (o instanceof Object[]) { print(Arrays.toString((Object [])o)); } else { print("" + o); } } void print(String s) { pw.print(s); } void println() { println(""); } void println(byte b) { println("" + b); } void println(int i) { println("" + i); } void println(long l) { println("" + l); } void println(double d) { println("" + d); } void println(char c) { println("" + c); } void println(Object o) { print(o); println(); } void println(String s) { pw.println(s); } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } long nextLong() throws IOException { return Long.parseLong(nextToken()); } double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } char nextChar() throws IOException { return (char) (br.read()); } String next() throws IOException { return nextToken(); } String nextLine() throws IOException { return br.readLine(); } int [] readInt(int size) throws IOException { int [] array = new int [size]; for (int i = 0; i < size; i++) { array[i] = nextInt(); } return array; } long [] readLong(int size) throws IOException { long [] array = new long [size]; for (int i = 0; i < size; i++) { array[i] = nextLong(); } return array; } double [] readDouble(int size) throws IOException { double [] array = new double [size]; for (int i = 0; i < size; i++) { array[i] = nextDouble(); } return array; } String [] readLines(int size) throws IOException { String [] array = new String [size]; for (int i = 0; i < size; i++) { array[i] = nextLine(); } return array; } }
Java
["4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2", "1\n42", "2\n1 1 1 1"]
2 seconds
["4 3 6 2", "42", "1 1"]
null
Java 8
standard input
[ "constructive algorithms", "number theory" ]
71dc07f0ea8962f23457af1d6509aeee
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a. All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
1,700
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
standard output
PASSED
5d48e92823ebed09bf983c2bb54da3f3
train_000.jsonl
1443890700
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as . For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows: Given all the numbers of the GCD table G, restore array a.
256 megabytes
import java.io.*; import java.util.*; public class Main { static InputReader in = new InputReader(System.in); static PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) { int n = in.nextInt(); int[] a = new int[n * n]; MyTreeMap t = new MyTreeMap(); for(int i=0; i < n * n; ++i) { a[i] = in.nextInt(); t.add(a[i]); } ArrayList<Integer> ans = new ArrayList<>(); while(ans.size() < n) { int M = t.lastKey(); t.del(M); ans.add(M); for(int i = ans.size() - 2; i >= 0; --i) { int x = ans.get(i); int y = ans.get(ans.size() - 1); int gcd = gcd(x, y); t.del(gcd); t.del(gcd); } } for(int x : ans) out.print(x + " "); out.close(); } static int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } static class MyTreeMap extends TreeMap<Integer, Integer> { void add(int n) { int x = getOrDefault(n, 0); put(n, x + 1); } void del(int n) { int x = get(n); if(x > 1) { put(n, x - 1); } else { remove(n); } } } } class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; public InputReader(InputStream st) { this.stream = st; } public int read() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } public String readString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } }
Java
["4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2", "1\n42", "2\n1 1 1 1"]
2 seconds
["4 3 6 2", "42", "1 1"]
null
Java 8
standard input
[ "constructive algorithms", "number theory" ]
71dc07f0ea8962f23457af1d6509aeee
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a. All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
1,700
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
standard output
PASSED
07d2102218a761918004f91785a036f6
train_000.jsonl
1443890700
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as . For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows: Given all the numbers of the GCD table G, restore array a.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.TreeMap; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Bat-Orgil */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskC solver = new TaskC(); solver.solve(1, in, out); out.close(); } static class TaskC { public static int gcd(int a, int b) { if (b == 0) { return Math.abs(a); } return gcd(b, a % b); } public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); TreeMap<Integer, Integer> map = new TreeMap(); for (int i = 0; i < n * n; i++) { int c = in.nextInt(); if (map.containsKey(c)) { map.put(c, map.get(c) + 1); } else { map.put(c, 1); } } int[] nums = new int[n]; for (int i = 0; i < n; i++) { int highest = map.lastKey(); if (map.get(highest) == 1) { map.remove(highest); } else { map.put(highest, map.get(highest) - 1); } out.print(highest + " "); nums[i] = highest; for (int j = 0; j < i; j++) { int gcd = gcd(nums[j], nums[i]); // System.out.println(gcd); if (map.get(gcd) == 2) { map.remove(gcd); } else { map.put(gcd, map.get(gcd) - 2); } } } } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
Java
["4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2", "1\n42", "2\n1 1 1 1"]
2 seconds
["4 3 6 2", "42", "1 1"]
null
Java 8
standard input
[ "constructive algorithms", "number theory" ]
71dc07f0ea8962f23457af1d6509aeee
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a. All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
1,700
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
standard output
PASSED
c547425985bdf81bcf0e4cf6ceb3d203
train_000.jsonl
1443890700
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as . For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows: Given all the numbers of the GCD table G, restore array a.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Scanner; public class CF_323_C { private static int gcd(int a, int b){ if(b == 0)return a; return gcd(b, a%b); } public static void main(String[] args) throws IOException{ PrintWriter pw = new PrintWriter(System.out, true); BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(input.readLine()); int N; String[] line = input.readLine().split(" "); HashMap<Integer, Integer> map = new HashMap<Integer, Integer>(); for(int i = 0; i < n*n; i++){ N = Integer.parseInt(line[i]); if(map.containsKey(N)){ map.put(N, map.get(N) + 1); }else{ map.put(N, 1); } } ArrayList<Integer> d = new ArrayList<Integer>(); for(int x: map.keySet()){ d.add(x); } Collections.sort(d); int a, b, c, g, l, m; ArrayList<Integer> ans = new ArrayList<Integer>(); for(int i = d.size() - 1; i >= 0; i--){ a = d.get(i); c = map.get(a); l = 0; // remove form prev. for(int x: ans){ g = gcd(x,a); if(g == a){ l++; } } for(int k = 1; k <= c; k++){ if(k*k + 2*l*k == map.get(a)){ b = k; for(int x: ans){ g = gcd(x,a); if(g != a){ map.put(g, map.get(g) - 2*k); } } for(int j = 0; j < b; j++){ ans.add(a); } break; } } if(ans.size() == n)break; } for(int x: ans){ pw.print(x+" "); } pw.println(); pw.close(); input.close(); } }
Java
["4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2", "1\n42", "2\n1 1 1 1"]
2 seconds
["4 3 6 2", "42", "1 1"]
null
Java 8
standard input
[ "constructive algorithms", "number theory" ]
71dc07f0ea8962f23457af1d6509aeee
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a. All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
1,700
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
standard output
PASSED
19f752e80768dae5662b014f81e235a5
train_000.jsonl
1443890700
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as . For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows: Given all the numbers of the GCD table G, restore array a.
256 megabytes
import java.io.InputStream; import java.io.OutputStream; import java.io.IOException; import java.util.ArrayList; import java.io.InputStream; import java.io.BufferedReader; import java.io.FileReader; import java.util.TreeMap; import java.io.InputStreamReader; import java.io.IOException; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.File; import java.io.FileNotFoundException; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Kartik Singal (ka4tik) */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastScanner in = new FastScanner(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskC solver = new TaskC(); solver.solve(1, in, out); out.close(); } static class TaskC { public void solve(int testNumber, FastScanner in, PrintWriter out) { int n = in.nextInt(); TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>(); for (int i = 0; i < n * n; i++) { int v = in.nextInt(); if (map.containsKey(v)) map.put(v, map.get(v) + 1); else map.put(v, 1); } ArrayList<Integer> ans = new ArrayList<Integer>(); for (int i = 0; i < n; i++) { int mx = map.lastKey(); for (int a : ans) { int g = MyUtils.gcd(mx, a); if (map.get(g) == 2) map.remove(g); else map.put(g, map.get(g) - 2); } ans.add(mx); if (map.get(mx) == 1) map.remove(mx); else map.put(mx, map.get(mx) - 1); } for (int a : ans) out.print(a + " "); } } static class MyUtils { public static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } } static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(File f) { try { br = new BufferedReader(new FileReader(f)); } catch (FileNotFoundException e) { e.printStackTrace(); } } public FastScanner(InputStream f) { br = new BufferedReader(new InputStreamReader(f)); } public String next() { while (st == null || !st.hasMoreTokens()) { String s = null; try { s = br.readLine(); } catch (IOException e) { e.printStackTrace(); } if (s == null) return null; st = new StringTokenizer(s); } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
Java
["4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2", "1\n42", "2\n1 1 1 1"]
2 seconds
["4 3 6 2", "42", "1 1"]
null
Java 8
standard input
[ "constructive algorithms", "number theory" ]
71dc07f0ea8962f23457af1d6509aeee
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a. All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
1,700
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
standard output
PASSED
aed00afb17bca8fff70322f1aa70ceb6
train_000.jsonl
1443890700
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as . For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows: Given all the numbers of the GCD table G, restore array a.
256 megabytes
import java.util.*; public class C { private static Map<Integer, Integer> map; public static void main(String[] args) { Scanner cin = new Scanner(System.in); int n = cin.nextInt(); int[] a = new int[n * n]; map = new HashMap<>(); for (int i = 0; i < n * n; i++) { a[i] = cin.nextInt(); Integer value = map.get(a[i]); if (value == null) { value = 0; } value++; map.put(a[i], value); } int[][] ans = new int[n][n]; int p = 0; for (Map.Entry<Integer, Integer> now : map.entrySet()) { if (now.getValue() % 2 == 1) { ans[p][p] = now.getKey(); p++; } } for (int i = 0; i < p; i++) { remove(ans[i][i], 1); for (int j = i + 1; j < p; j++) { ans[j][i] = ans[i][j] = gcd(ans[i][i], ans[j][j]); remove(ans[i][j], 2); } } while (!map.isEmpty()) { int next = findMax(); ans[p][p] = next; remove(next, 1); for (int i = 0; i < p; i++) { ans[i][p] = ans[p][i] = gcd(ans[i][i], ans[p][p]); remove(ans[i][p], 2); } p++; } for (int i = 0; i < n; i++) { System.out.print(ans[i][i] + " "); } cin.close(); } private static int findMax() { int ans = 0; for (int now : map.keySet()) { if (now > ans) ans = now; } return ans; } private static void remove(int value, int num) { int ans = map.get(value) - num; if (ans != 0) { map.put(value, ans); } else { map.remove(value); } } public static int gcd(int m, int n) { if (m < n) { int t = n; n = m; m = t; } int r; do { r = m % n; m = n; n = r; } while (r != 0); return m; } }
Java
["4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2", "1\n42", "2\n1 1 1 1"]
2 seconds
["4 3 6 2", "42", "1 1"]
null
Java 8
standard input
[ "constructive algorithms", "number theory" ]
71dc07f0ea8962f23457af1d6509aeee
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a. All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
1,700
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
standard output
PASSED
3a52b6af6e596f8b469ceeb91d41b18c
train_000.jsonl
1443890700
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as . For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows: Given all the numbers of the GCD table G, restore array a.
256 megabytes
import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.Scanner; import java.util.TreeMap; public class GCDTable { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); List<Integer> res = new ArrayList<>(); List<Integer> gcdTable = getList(sc, n * n); TreeMap<Integer, Integer> counts = new TreeMap<Integer, Integer>(Comparator.<Integer>reverseOrder()); for (Integer num : gcdTable) { Integer count = counts.get(num); if (count == null) { count = 1; } else { count = count + 1; } counts.put(num, count); } while (!counts.isEmpty()) { Integer num = counts.firstKey(); for (Integer r : res) { int gcd = gcd(r, num); dec(counts, gcd); dec(counts, gcd); } res.add(num); dec(counts, num); } StringBuilder sb = new StringBuilder(); for (Integer re : res) { sb.append(re).append(" "); } System.out.println(sb.toString().trim()); } private static void dec(TreeMap<Integer, Integer> counts, Integer num) { Integer count = counts.get(num); if (count == 1) { counts.remove(num); } else { counts.put(num, count - 1); } } private static int[] getArr(Scanner sc, int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); } return a; } private static List<Integer> getList(Scanner sc, int n) { List<Integer> list = new ArrayList<>(); for (int i = 0; i < n; i++) { list.add(sc.nextInt()); } return list; } public static int gcd(int a, int b) { if (a == 0) { return b; } if (a > b) { return gcd(a % b, b); } else { return gcd(b % a, a); } } }
Java
["4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2", "1\n42", "2\n1 1 1 1"]
2 seconds
["4 3 6 2", "42", "1 1"]
null
Java 8
standard input
[ "constructive algorithms", "number theory" ]
71dc07f0ea8962f23457af1d6509aeee
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a. All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
1,700
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
standard output
PASSED
6e89d2d25ad311278764d6850084cba6
train_000.jsonl
1443890700
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as . For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows: Given all the numbers of the GCD table G, restore array a.
256 megabytes
import java.util.*; public class C { static HashMap<Integer, Integer> hash = new HashMap<>(); public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int max = 0; for (int i = 0; i < N * N; i++) { int x = sc.nextInt(); if (hash.containsKey(x)) hash.put(x, hash.get(x) + 1); else hash.put(x, 1); } List<Integer> ans = new ArrayList<>(); for (int i = 0; i < N ; i++) { max = findMaxInHash(); for (Integer found : ans) { int gcd = gcd(found, max); removeFromHash(gcd); removeFromHash(gcd); } removeFromHash(max); ans.add(max); } ans.stream().forEach(x -> System.out.print(x + " ")); } private static int findMaxInHash() { int max = 0; for (Map.Entry<Integer, Integer> e : hash.entrySet()) { if (e.getValue() > 0) max = Math.max(max, e.getKey()); } return max; } private static void removeFromHash(int gcd) { hash.put(gcd, hash.get(gcd) - 1); } public static int gcd(int x, int y) { if (y == 0) return x; else return gcd(y, x % y); } }
Java
["4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2", "1\n42", "2\n1 1 1 1"]
2 seconds
["4 3 6 2", "42", "1 1"]
null
Java 8
standard input
[ "constructive algorithms", "number theory" ]
71dc07f0ea8962f23457af1d6509aeee
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a. All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
1,700
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
standard output
PASSED
271a77819a743cdbc35c0fb2e9c75446
train_000.jsonl
1443890700
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as . For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows: Given all the numbers of the GCD table G, restore array a.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.TreeMap; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Hieu Le */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskC solver = new TaskC(); solver.solve(1, in, out); out.close(); } static class TaskC { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); int cnt = n * n; int[] a = new int[cnt]; TreeMap<Integer, Integer> map = new TreeMap<>(); for (int i = 0; i < cnt; i++) { a[i] = in.nextInt(); if (!map.containsKey(a[i])) map.put(a[i], 1); else map.put(a[i], map.get(a[i]) + 1); } int[] res = new int[n]; for (int i = 0; i < n; i++) { res[i] = map.lastKey(); if (map.get(res[i]) == 1) map.remove(res[i]); else map.put(res[i], map.get(res[i]) - 1); for (int j = 0; j < i; j++) { int gcd = findGcd(res[i], res[j]); if (map.get(gcd) == 2) map.remove(gcd); else map.put(gcd, map.get(gcd) - 2); } out.print(res[i] + " "); } } private int findGcd(int a, int b) { int temp; while (b > 0) { temp = b; b = a % b; a = temp; } return a; } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
Java
["4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2", "1\n42", "2\n1 1 1 1"]
2 seconds
["4 3 6 2", "42", "1 1"]
null
Java 8
standard input
[ "constructive algorithms", "number theory" ]
71dc07f0ea8962f23457af1d6509aeee
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a. All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
1,700
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
standard output
PASSED
e4f695117b147b4dec34c3dd6861910a
train_000.jsonl
1443890700
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as . For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows: Given all the numbers of the GCD table G, restore array a.
256 megabytes
import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; import java.lang.*; public class Third { //static long m=1000000007; static BigInteger ways(int N, int K) { BigInteger ret = BigInteger.ONE; for(int i=N;i>=N-K+1;i--) { ret = ret.multiply(BigInteger.valueOf(i)); } for (int j = 1; j<=K; j++) { ret = ret.divide(BigInteger.valueOf(j)); } ret=ret.mod(BigInteger.valueOf(1000000007)); return ret; } public static int prime(int n) { int f=1; if(n==1) return 0; for(int i=2;i<=(Math.sqrt(n));) { if(n%i==0) { f=0; break; } if(i==2) i++; else i+=2; } if(f==1) return 1; else return 0; } /*public static long gcd(long x,long y) { if(x%y==0) return y; else return gcd(y,x%y); }*/ public static BigInteger fact(int n) { BigInteger f=BigInteger.ONE; for(int i=1;i<=n;i++) { f=f.multiply(BigInteger.valueOf(i)); } //f=f.mod(BigInteger.valueOf(m)); return f; } public static int gcd(int x,int y) { if(x%y==0) return y; else return gcd(y,x%y); } public static int max(int a,int b) { if(a>b) return a; else return b; } public static int min(int a,int b) { if(a>b) return b; else return a; } static long ncr(long n,long k) { long w=1; for(long i=n,j=1;i>=n-k+1;i--,j++) { w=w*i; w=w/j; w%=1000000007; } return w; } static class Pair implements Comparable<Pair> { int a,b; Pair (int a,int b) { this.a=a; this.b=b; } public int compareTo(Pair o) { // TODO Auto-generated method stub if(this.a!=o.a) return Integer.compare(this.a,o.a); else return Integer.compare(this.b, o.b); //return 0; } } public static void main(String[] args) throws Exception{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb=new StringBuilder(""); //String line=br.readLine().trim(); //int t=Integer.parseInt(br.readLine()); // while(t-->0) //{ //int n=Integer.parseInt(br.readLine()); //long n=Long.parseLong(br.readLine()); //line=br.readLine().trim(); //String l[]=br.readLine().split(" "); //int m=Integer.parseInt(l[0]); //int k=Integer.parseInt(l[1]); //l=br.readLine().split(" "); //long m=Long.parseLong(l[0]); //long n=Long.parseLong(l[1]); //char ch=a.charAt(); // char c[]=new char[n]; //String l[]=br.readLine().split(" "); //l=br.readLine().split(" "); /*int a[]=new int[n]; for(int i=0;i<n;i++) { a[i]=Integer.parseInt(l[i]); }*/ /*long a[]=new long[n]; for(int i=0;i<n;i++) { a[i]=Long.parseLong(l[i]); }*/ /*int a[][]=new int[n][n]; for(int i=0;i<n;i++) { l=br.readLine().split(" "); for(int j=0;j<n;j++) { a[i][j]=Long.parseLong(l[j]); } }*/ // String a=br.readLine(); // char a[]=c.toCharArray(); //char ch=l[0].charAt(0); //HashMap<Integer,Integer>hm=new HashMap<Integer,Integer>(); //HashMap<Integer,String>hm=new HashMap<Integer,String>(); //HashMap<Integer,Long>hm=new HashMap<Integer,Long>(); //hm.put(1,1); //HashSet<Integer>hs=new HashSet<Integer>(); //HashSet<Long>hs=new HashSet<Long>(); //HashSet<String>hs=new HashSet<String>(); //hs.add(x); //Stack<Integer>s=new Stack<Integer>(); //s.push(x); //s.pop(x); //Queue<Integer>q=new LinkedList<Integer>(); //q.add(x); //q.remove(x); //ArrayList<Integer>ar=new ArrayList<Integer>(); //long x=Long.parseLong(l[0]); //int min=100000000; //long c1=(long)Math.ceil(n/(double)a); //Arrays.sort(a); // int f1[]=new int[26]; //int f2[]=new int[26]; /*for(int i=0;i<n;i++) { int x=a.charAt(0); f1[x-97]++; }*/ /*for(int i=0;i<n;i++) { }*/ /*for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { } }*/ /*while(q--) { l=br.readLine().split(" "); int n=Integer.parseInt(l[0]); int k=Integer.parseInt(l[1]); } */ /*if(f==1) System.out.println("Yes"); else System.out.println("No");*/ //System.out.print(""); //sb.append(""); //sb.append("").append("\n"); //int t=Integer.parseInt(br.readLine()); // while(t-->0) //{ //int n=Integer.parseInt(br.readLine()); //String l[]=br.readLine().split(" "); //int m=Integer.parseInt(l[0]); //int k=Integer.parseInt(l[1]); //l=br.readLine().split(" "); //String l[]=br.readLine().split(" "); //l=br.readLine().split(" "); /*int a[]=new int[n]; for(int i=0;i<n;i++) { a[i]=Integer.parseInt(l[i]); }*/ /*for(int i=0;i<n;i++) { }*/ /*for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { } }*/ int n=Integer.parseInt(br.readLine()); String l[]=br.readLine().split(" "); int b[]=new int[n]; int a[]=new int[n*n]; for(int i=1;i<=n*n;i++) { a[i-1]=Integer.parseInt(l[i-1]); } int c=0; HashMap<Integer,Integer>hm=new HashMap<Integer,Integer>(); Arrays.sort(a); int r=0; int g=a[n*n-1]; for(int i=(n*n)-1;i>=0;i--) { r++; if(r<3) { b[c++]=a[i]; if(r==2) { g=gcd(b[c-1],b[c-2]); hm.put(g, 2); } } else { if(hm.containsKey(a[i])) { int x=hm.get(a[i]); if(x>1) hm.put(a[i],x-1); else hm.remove(a[i]); } else { for(int j=0;j<c;j++) { g=gcd(b[j],a[i]); if(hm.containsKey(g)) { int x=hm.get(g); hm.put(g,x+2); } else hm.put(g,2); } b[c++]=a[i]; } } } for(int i=0;i<n;i++) System.out.print(b[i]+" "); //} } }
Java
["4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2", "1\n42", "2\n1 1 1 1"]
2 seconds
["4 3 6 2", "42", "1 1"]
null
Java 8
standard input
[ "constructive algorithms", "number theory" ]
71dc07f0ea8962f23457af1d6509aeee
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a. All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
1,700
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
standard output
PASSED
4f2de08dfd2d5f38eb3583b0c581e361
train_000.jsonl
1443890700
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as . For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows: Given all the numbers of the GCD table G, restore array a.
256 megabytes
//package Codeforces; import java.io.*; import java.util.*; /** * Created by tawsif on 10/10/15. * Time: 3:50 PM */ public class GCDTable323C { final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null; PrintWriter out; long timeBegin, timeEnd; // Write Solution Here int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } private void solve() throws IOException { int n = Reader.nextInt(); // Variable Declared Automatically For First Input int[] array = new int[n*n]; HashMap<Integer , int [] > table = new HashMap<>(); ArrayList<Integer> outputElement = new ArrayList<>(n); for (int i = 0; i < n * n; i++) { array[i] = Reader.nextInt(); table.put(array[i] , new int[1]); } Arrays.sort(array); for (int i = n * n -1; i >= 0; i--) { if(table.get(array[i])[0]==0 ) { for (int x : outputElement) { int gcd = gcd(array[i] , x); table.get(gcd)[0]+= 2; } outputElement.add(array[i]); } else table.get(array[i])[0]-- ; } for (int i = outputElement.size() - 1; i >= 0; i--) { out.print(outputElement.get(i) + " "); } } public static void main(String[] args) throws IOException { new GCDTable323C().runIO(); } public void runIO() throws IOException { timeBegin = System.currentTimeMillis(); InputStream inputStream; OutputStream outputStream; if (ONLINE_JUDGE) { inputStream = System.in; Reader.init(inputStream); outputStream = System.out; out = new PrintWriter(outputStream); } else { inputStream = new FileInputStream("input.txt"); Reader.init(inputStream); out = new PrintWriter("output.txt"); } solve(); // Start Main Problem Solving out.flush(); out.close(); timeEnd = System.currentTimeMillis(); System.err.println("Time = " + (timeEnd - timeBegin)); } static class Reader { static BufferedReader reader; static StringTokenizer tokenizer; /** * call this method to initialize reader for InputStream */ static void init(InputStream input) { reader = new BufferedReader(new InputStreamReader(input)); tokenizer = new StringTokenizer(""); } /** * get next word */ static String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } static int nextInt() throws IOException { return Integer.parseInt(next()); } static long nextLong() throws IOException { return Long.parseLong(next()); } static double nextDouble() throws IOException { return Double.parseDouble(next()); } } }
Java
["4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2", "1\n42", "2\n1 1 1 1"]
2 seconds
["4 3 6 2", "42", "1 1"]
null
Java 8
standard input
[ "constructive algorithms", "number theory" ]
71dc07f0ea8962f23457af1d6509aeee
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a. All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
1,700
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
standard output
PASSED
8022c7f333a511707dbdaf5164db48db
train_000.jsonl
1443890700
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as . For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows: Given all the numbers of the GCD table G, restore array a.
256 megabytes
import java.io.*; import java.util.Map; import java.util.SortedMap; import java.util.StringTokenizer; import java.util.TreeMap; public class Main { private final InputReader in; private final PrintWriter out; public Main(final InputReader in, final PrintWriter out) { this.in = in; this.out = out; } private static PrintWriter getOutput(final String filename) throws IOException { if (filename == null || filename.isEmpty()) { return new PrintWriter(new OutputStreamWriter(System.out)); } else { return new PrintWriter(new FileWriter(filename + ".out")); } } public static void main(final String[] args) throws NumberFormatException, IOException { final String filename = ""; final long time = System.currentTimeMillis(); try (final InputReader in = new InputReader(filename); final PrintWriter out = getOutput(filename)) { new Main(in, out).solve(); } // System.err.println("Running time: " + (System.currentTimeMillis() - time)); } <K> void add(final Map<K, Integer> map, final K key) { map.put(key, map.containsKey(key) ? map.get(key) + 1 : 1); } <K> void delete(final Map<K, Integer> map, final K key, final int count) { final int newCount = map.get(key) - count; if (newCount < 0) { throw new RuntimeException(); } else if (newCount == 0) { map.remove(key); } else { map.put(key, newCount); } } private void solve() throws IOException { final int n = in.nextInt(); final SortedMap<Long, Integer> map = new TreeMap<>(); for (int i = 0; i < n * n; i++) add(map, in.nextLong()); final long[] result = new long[n]; for (int i = 0; i < n; i++) { final long next = map.lastKey(); result[i] = next; delete(map, next, 1); for (int j = 0; j < i; j++) { delete(map, gcd(next, result[j]), 2); } } for (int i = 0; i < n; i++) { out.print(result[i]); out.print(' '); } out.println(); } private long gcd(final long a, final long b) { return b > 0 ? gcd(b, a % b) : a; } } class InputReader implements Closeable { private StringTokenizer st; private final BufferedReader in; public InputReader(final String filename) throws IOException { if (filename == null || filename.isEmpty()) in = new BufferedReader(new InputStreamReader(System.in)); else in = new BufferedReader(new FileReader(filename + ".in")); } public boolean hasNextToken() throws IOException { while (st == null || !st.hasMoreTokens()) { String line = in.readLine(); if (line == null) return false; st = new StringTokenizer(line); } return true; } public String nextToken() throws IOException { while (st == null || !st.hasMoreTokens()) { String line = in.readLine(); if (line == null) return null; st = new StringTokenizer(line); } return st.nextToken(); } public String readLine() throws IOException { return in.readLine(); } public int nextInt() throws NumberFormatException, IOException { return Integer.parseInt(nextToken()); } public long nextLong() throws NumberFormatException, IOException { return Long.parseLong(nextToken()); } public double nextDouble() throws NumberFormatException, IOException { return Double.parseDouble(nextToken()); } @Override public void close() throws IOException { in.close(); } }
Java
["4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2", "1\n42", "2\n1 1 1 1"]
2 seconds
["4 3 6 2", "42", "1 1"]
null
Java 8
standard input
[ "constructive algorithms", "number theory" ]
71dc07f0ea8962f23457af1d6509aeee
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a. All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
1,700
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
standard output
PASSED
888262bebde60e271e19ed5dfdeeb408
train_000.jsonl
1443890700
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as . For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows: Given all the numbers of the GCD table G, restore array a.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.io.IOException; import java.io.InputStreamReader; import java.util.TreeMap; import java.util.StringTokenizer; import java.io.BufferedReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Aldo Culquicondor */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskC solver = new TaskC(); solver.solve(1, in, out); out.close(); } static class TaskC { int n; int[] g; int[] sol; TreeMap<Integer, Integer> map; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } void remove(int v) { map.put(v, map.get(v) - 1); if (map.get(v) == 0) map.remove(v); } void add(int d) { map.put(d, map.getOrDefault(d, 0) + 1); } public void solve(int testNumber, InputReader in, PrintWriter out) { n = in.nextInt(); g = new int[n * n]; sol = new int[n]; map = new TreeMap<>(); IOUtils.read(in, g); Arrays.sort(g); int id = 0, q = 0; while (id < n * n) { if (id + 1 < n * n && g[id] == g[id + 1]) { add(g[id]); id += 2; } else { sol[q++] = g[id++]; } } for (int i = 0; i < q; ++i) for (int j = i + 1; j < q; ++j) remove(gcd(sol[i], sol[j])); while (!map.isEmpty()) { sol[q++] = map.lastKey(); sol[q++] = map.lastKey(); remove(map.lastKey()); for (int i = 0; i < q - 2; ++i) remove(gcd(sol[i], sol[q - 2])); for (int i = 0; i < q - 1; ++i) remove(gcd(sol[i], sol[q - 1])); } IOUtils.print(out, sol); } } static class IOUtils { public static void read(InputReader in, int A[], int start, int end) { for (int i = start; i < end; ++i) A[i] = in.nextInt(); } public static void read(InputReader in, int A[]) { read(in, A, 0, A.length); } public static void print(PrintWriter out, int A[], int start, int end) { if (start < end) out.print(A[start]); for (int i = start + 1; i < end; ++i) out.printf(" %d", A[i]); } public static void print(PrintWriter out, int A[]) { print(out, A, 0, A.length); } } static class InputReader { private BufferedReader reader; private StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 65536); tokenizer = null; } public String next() { String line; while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { line = reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } if (line == null) throw new UnknownError(); tokenizer = new StringTokenizer(line); } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
Java
["4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2", "1\n42", "2\n1 1 1 1"]
2 seconds
["4 3 6 2", "42", "1 1"]
null
Java 8
standard input
[ "constructive algorithms", "number theory" ]
71dc07f0ea8962f23457af1d6509aeee
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a. All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
1,700
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
standard output