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
public class cie {
	public static void main(String[] args) {
		int d = cielib.podajD();
		int r = cielib.podajR();
		int t[] = new int[d];
		int l[] = new int[d];
		int h[] = new int[d];

		for (int i = 0; i < d; ++i) {
			h[i] = r;
		}

		cielib.czyCieplo(t);

		while (true) {
			boolean found = true;
			
			for (int i = 0; i < d; ++i) {
				if (l[i] < h[i]) {
					boolean f2 = false;
					if (t[i] == l[i])
						t[i] = h[i];
					else
						t[i] = l[i];
					
					while (cielib.czyCieplo(t) == 1) {
						f2 = true;
						if (t[i] == l[i]) {
							h[i] = (l[i] + h[i] + 1) / 2 - 1;
							t[i] = h[i];
						} else {
							l[i] = (l[i] + h[i]) / 2 + 1;
							t[i] = l[i];
						}
						if (l[i] == h[i])
							break;
					}
					if (l[i] < h[i])
						found = false;
					
					if (!f2)
					{
						int tt = t[i];
						t[i] = l[i] + h[i] / 2;
						if (cielib.czyCieplo(t) == 1)						
						{
							if (tt == l[i])
								l[i] += (h[i] - l[i]) / 4 + 1;
							else
								h[i] -= (h[i] - l[i]) / 4 + 1;
						}
					}
				}
			}
			if (found)
				break;

		}
		cielib.znalazlem(t);
	}
}