import java.util.Arrays; public class cie { public static void main(String[] args) { int d = cielib.podajD(); int r = cielib.podajR(); int[] c = new int[d]; int[] u = new int[d]; int[] l = new int[d]; int v = r >> 1; for (int i = 0; i < d; i++) { c[i] = v; u[i] = r; l[i] = 0; } int error = v + 1; while (error != 0) { int prevError = error; error = 0; for (int i = 0; i<d; i++) { if (u[i] == l[i]) { // error = 0 here continue; } // if (prevError > u[i] - l[i]) { // error = Math.max(u[i] - l[i], error); // continue; // } if (u[i] == l[i] + 1) { if (l[i] > 0) { c[i] = l[i]-1; cielib.czyCieplo(c); c[i] = u[i]; if (cielib.czyCieplo(c) == 1) { c[i] = u[i]; } else { c[i] = l[i]; } } else { c[i] = u[i]+1; cielib.czyCieplo(c); c[i] = l[i]; if (cielib.czyCieplo(c) == 1) { c[i] = l[i]; } else { c[i] = u[i]; } } l[i] = c[i]; u[i] = c[i]; } else { // TODO: think about order - lower to up or up to lower ? c[i] = l[i]; // System.out.print(Arrays.toString(c) + " -> "); cielib.czyCieplo(c); c[i] = u[i]; // System.out.println(Arrays.toString(c)); if (cielib.czyCieplo(c) == 1) { // is closer // u[i] - p[i] < p[i] - l[i] // u[i] + l[i] < 2p[i] // TODO edge cases? is this strong enough ? l[i] = (u[i] + l[i]) >> 1; } else { // u[i] - p[i] >= p[i] - l[i] // u[i] + l[i] >= 2p[i] u[i] = (int) Math.ceil((u[i] + l[i]) / 2.); // u[i] = (u[i] + l[i]) >> 1; } } // System.out.println("" + l[i] + " " + u[i]); c[i] = (u[i] + l[i]) >> 1; error = Math.max(error, u[i] - l[i]); } } cielib.znalazlem(c); } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | import java.util.Arrays; public class cie { public static void main(String[] args) { int d = cielib.podajD(); int r = cielib.podajR(); int[] c = new int[d]; int[] u = new int[d]; int[] l = new int[d]; int v = r >> 1; for (int i = 0; i < d; i++) { c[i] = v; u[i] = r; l[i] = 0; } int error = v + 1; while (error != 0) { int prevError = error; error = 0; for (int i = 0; i<d; i++) { if (u[i] == l[i]) { // error = 0 here continue; } // if (prevError > u[i] - l[i]) { // error = Math.max(u[i] - l[i], error); // continue; // } if (u[i] == l[i] + 1) { if (l[i] > 0) { c[i] = l[i]-1; cielib.czyCieplo(c); c[i] = u[i]; if (cielib.czyCieplo(c) == 1) { c[i] = u[i]; } else { c[i] = l[i]; } } else { c[i] = u[i]+1; cielib.czyCieplo(c); c[i] = l[i]; if (cielib.czyCieplo(c) == 1) { c[i] = l[i]; } else { c[i] = u[i]; } } l[i] = c[i]; u[i] = c[i]; } else { // TODO: think about order - lower to up or up to lower ? c[i] = l[i]; // System.out.print(Arrays.toString(c) + " -> "); cielib.czyCieplo(c); c[i] = u[i]; // System.out.println(Arrays.toString(c)); if (cielib.czyCieplo(c) == 1) { // is closer // u[i] - p[i] < p[i] - l[i] // u[i] + l[i] < 2p[i] // TODO edge cases? is this strong enough ? l[i] = (u[i] + l[i]) >> 1; } else { // u[i] - p[i] >= p[i] - l[i] // u[i] + l[i] >= 2p[i] u[i] = (int) Math.ceil((u[i] + l[i]) / 2.); // u[i] = (u[i] + l[i]) >> 1; } } // System.out.println("" + l[i] + " " + u[i]); c[i] = (u[i] + l[i]) >> 1; error = Math.max(error, u[i] - l[i]); } } cielib.znalazlem(c); } } |