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
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
#include "cielib.h"
using namespace std;

int main()
{
	int d, r,k,p,pr,res;
	r = podajR();
	d = podajD();
	k = podajK();
	int* t = new int[d];
	int* t2 = new int[d];
	int* tab = new int[d];

	p = r;
    pr = p % 2;
    p = p / 2;
	pr = pr + p;

	for (int a = 0; a < d; a++)
	{
		tab[a] = 3;
		t[a] = pr;
		t2[a] = pr;
	}

	int flaga = 0;
	if (r % 2)
		flaga = 1;

	
	while (p > 0)
	{
		for (int a=0;a<d;a++)
		{
			if (tab[a] != 0)
			{
				t2[a] = t[a] + p;
				res = czyCieplo(t2); 
				k--;
				t2[a] = t[a] - p;
				res = czyCieplo(t2); 
				k--;
				if (res)
					tab[a] = 1;
				else
				{
					t2[a] = t[a] + p;
					res = czyCieplo(t2); 
					k--;
					if (res)
						tab[a] = 2;
					else
						tab[a] = 0;
				}
			}

		}

		pr = p % 2;
		p = p / 2;
		pr = pr + p;

		for (int a=0;a<d;a++)
		{
			if (tab[a] == 1)
				t[a] = t[a] - pr;
			if (tab[a] == 2)
				t[a] = t[a] + pr;
			t2[a] = t[a];
		}
	}

	if (flaga && k >= d * 3)
	{
		p = 1;
		pr = 1;
		for (int a=0;a<d;a++)
		{
				t2[a] = t[a] + p;
				res = czyCieplo(t2);
				k--;
				t2[a] = t[a] - p;
				res = czyCieplo(t2); 
				k--;
				if (res)
					tab[a] = 1;
				else
				{
					t2[a] = t[a] + p;
					res = czyCieplo(t2); 
					k--;
					if (res)
						tab[a] = 2;
					else
						tab[a] = 0;
				}
		}
		for (int a=0;a<d;a++)
		{
			if (tab[a] == 1)
				t[a] = t[a] - pr;
			if (tab[a] == 2)
				t[a] = t[a] + pr;
			t2[a] = t[a];
		}
	}
	znalazlem(t);
	return 0;
}