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
#include <algorithm>
#include <utility>
#include <cstdio>

#include "cielib.h"
using namespace std;

void print(char c, int *t, int d) {
	return;
	printf("%c: ", c);
	for(int i = 0; i < d; ++i)
		printf("%d", t[i]);
	printf("\n");
}

bool find(int *t, int *ends, int i, int d) {
	int start = t[i];
	int end = ends[i];
	if (start == end)
		return false;
	int middle = (start + end) / 2;
	print('a', t, d);
	t[i] = end;
	print('b', t, d);
	if (czyCieplo(t)) {
		t[i] = middle + 1;
		czyCieplo(t);
		return true;
	}
	t[i] = start;
	if (czyCieplo(t)) {
		ends[i] = middle - 1;
		return true;
	}
	return false;
}

int main() {
	int d = podajD();
	int r = podajR();
	int t[d];
	int ends[d];
	for(int i = 0; i < d; ++i) {
		t[i] = 0; ends[i] = r;
	}

	czyCieplo(t);
	bool ready, changed;
	do {
		ready = true;
		do {
			changed = false;
			for (int i = 0; i < d; ++i) {
				if (find(t, ends, i, d))
					changed = true;
			}
		} while(changed);
		for (int i = 0; i < d; ++i) {
			int old = t[i];
			if (old != (t[i] = (t[i] + ends[i]) / 2))
				ready = false;
		}
		print('d', ends, d);
		print('c', t, d);
	} while(!ready);

	znalazlem(t);
}