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
#include "cielib.h"
#include <cstdio>
#include <unistd.h>
int t[600];
int M[600], m[600], mx[600], mxc, d, r;
const bool pr = true;
void upd() {
	for (int i = 0; i < d; i++) {
		t[i] = (m[i]+M[i])/2;
	}
}
int isMax(int c) {
	bool a=0,b=0;
	if (t[c] < r) {
		t[c]++;
		b = czyCieplo(t);
		t[c]--;
		a = czyCieplo(t);
		if (t[c] == 0 && a) return 0;
	}
	if (t[c] > 0) {
		t[c]--;
		a |= czyCieplo(t);
		t[c]++;
		b |= czyCieplo(t);
		if (t[c] == r && b) return 0;
	}
	return a*1+b*2;
}
int main() {
	d = podajD();
	r = podajR();
	for(int i = 0; i < d; ++i) {
		M[i] = r;
	}
	while (1) {
		mxc = 0;
		upd();
		bool u = false;
		for (int i = 0; i < d; i++) {
			if (M[i] - m[i] < 3) continue;
			u=true;
			bool a,b=0;
			int mid = (m[i]+M[i])/2;
			t[i]=m[i];
			czyCieplo(t);
			t[i]=M[i];
			a=czyCieplo(t);
			if (a) {
				m[i] = mid+1;
			} else {
				t[i] = m[i];
				b=czyCieplo(t);
				if (b) {
					M[i] = mid-1;
				} else {
					t[i] = m[i] = M[i] = mid;
				}
			}
			t[i] = (m[i]+M[i])/2;
			if(pr)printf("%d  %d/%d (%d, %d)     ", t[i], m[i], M[i], a?1:0, b?1:0);
		}
		if(pr)printf("\n");
		if (!u) {
			while(1) {
				int chg = false;
				for (int i = 0; i < d; i++) {
					int cm = isMax(i);
					if(pr)printf("[%d] %d is %d    ", t[i], i, cm);
					if (cm == 3 || cm == 0)
						continue;
					chg = true;
					if (cm == 1) {
						t[i]--;
					} else
						t[i]++;

				}
				if (!chg)
					znalazlem(t);
				if(pr)printf("\n");
			}
		}
	}
}