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

#include "cielib.h"
using namespace std;

int D, R;
int *offset, *found_coord, *translated;

int * translatePosition(int const * const position) {
	for(int d = 0, p = 0 ; d != D ; ++d)
		if(found_coord[d] != -1)
			translated[d] = found_coord[d];
		else
			translated[d] = position[p++] + offset[d];
	return translated;
}

int isCloser(int const * const position) {
	return czyCieplo(translatePosition(position));
}

int translateD(int d) {
    for(int where = 0 ;; ++where)
        if(found_coord[where] == -1 && d-- == 0)
			return where;
}

void foundCoord(int d, int const coord) {
	d = translateD(d);
	found_coord[d] = coord + offset[d];
}

void addOffset(int d, int const offset_add) {
	d = translateD(d);
	offset[d] += offset_add;
}


int *position, *result;

void findTarget(int const D, int const R) {
	if(D == 0)
		return;

	if(R == 2) {
		fill(position + 1, position + D, 1);
		position[0] = 0;
		isCloser(position);

		position[0] = 2;
        if(isCloser(position) == 1) {
			foundCoord(0, 2);
        } else {
			position[0] = 0;
			foundCoord(0, isCloser(position) == 1 ? 0 : 1);
        }

		return findTarget(D - 1,  2);
	}

	fill(position, position + D, R/2);
    for(int d = 0 ; d != D ; ++d) {
		position[d] = 0;
		isCloser(position);

		position[d] = R;
		result[d] = isCloser(position);
		position[d] = R/2;
    }

	for(int d = 0 ; d != D ; ++d)
		if(result[d] == 1)
			addOffset(d, R/2);

	return findTarget(D,  R - R/2);
}

void testCase() {
	D = podajD();
	R = podajR();

	offset = new int[D];
	fill(offset, offset + D, 0);

	found_coord = new int[D];
	fill(found_coord, found_coord + D, -1);

	translated = new int[D];

	position = new int[D];

	result = new int[D];

	findTarget(D, R);
	znalazlem(found_coord);

	delete[] offset;
	delete[] found_coord;
	delete[] translated;
	delete[] position;
	delete[] result;
}

int main() {
	testCase();
}