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
#include "cielib.h"

// #define DEBUG 1
#ifdef DEBUG
#include <stdio.h>
#endif

#define S 505
int r, d, k, r2, i, w;
int A[S], B[S], C[S], *a, *b, *c, lc;
int main()
{
	d = podajD();
	k = podajK();
	r = podajR();

#ifdef DEBUG
	printf("Main (d=%d, k=%d, r=%d)\n", d, k, r);
#endif
	w = r >> 1;
	for(i = 0, b = B, c = C; i < d; ++i, ++b, ++c)
	{
		*b = r;
		*c = w;
	}
	for(i = 0, a = A, b = B, c = C; i < d; ++i, ++a, ++b, ++c)
	{
		*b = r;
		while(1)
		{
			w = (*b - *a) >> 1;
			if(w)
			{
#ifdef DEBUG
				printf("(%d: [%d %d] (w/2=%d))\n", i, *a, *b, w);
#endif
				*c = *a + (w >> 1);
				lc = czyCieplo(C);
#ifdef DEBUG
				printf("%i: f(%d) = %d\n", i, *c, lc);
#endif

				--k;
				*c += w;
				--k;
				lc = czyCieplo(C);
#ifdef DEBUG
				printf("%i: f(%d) = %d)\n", i, *c, lc);
#endif
				if(lc)
				{
					*a += w;
#ifdef DEBUG
					printf("%i: a = %d\n", i, *a);
#endif
				}
				else
				{
					*b = *a + w;
#ifdef DEBUG
					printf("%i: b = %d\n", i, *a);
#endif
				}
			}
			else
			{
				*c = *a;
				--k;
				lc = czyCieplo(C);
				*c = *b;
				--k;
				lc = czyCieplo(C);
				if(!lc)
				{
					*c = *a;
				}
				break;
			}
		}
#ifdef DEBUG
		printf("Out (%d: [%d %d]) => %d \n", i, *a, *b, *c);
#endif

	}
	znalazlem(C);
	return 0;
}