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

const int MAXD = 512;

int low[MAXD];
int high[MAXD];
int D, R, K;

void midpoint(int poz[]) {
	for (int i=0; i<D; ++i)
		poz[i] = (low[i]+high[i])/2;
}
int find_widest_dimension() {
	int maxi = -1;
	int max = 0;
	for (int i=0; i<D; ++i) {
		if (high[i]-low[i] > max) {
			max = high[i]-low[i];
			maxi = i;
		}
	}
	return maxi;
}

int main() {
	D = podajD();
	R = podajR();
	K = podajK();
	
	int test[MAXD];
	
	for (int i=0; i<D; ++i)
		high[i] = R;
	while (1) {
//		cout<<endl;
//		znalazlem(low);
//		znalazlem(high);
		int dim = find_widest_dimension();
		if (dim == -1)
			break;

		if (high[dim]-low[dim]>1) {
			midpoint(test);
			test[dim] = low[dim];
			czyCieplo(test);
			test[dim] = high[dim];
			if (czyCieplo(test)) {
				low[dim] = low[dim] + (high[dim]-low[dim])/2 + 1;
			} else {
				//test[dim] = low[dim];
				//if (czyCieplo(test)) {
					high[dim] = low[dim] + (high[dim]-low[dim])/2
						+((high[dim]-low[dim])>2);
					
				//} else {
				//	cout<<"Err";
				//}
			}
		} else {
//			cout<<"asdf"<<endl;
			midpoint(test); // will set to "low" on all coords
			czyCieplo(test);
			test[dim]++;
			if (czyCieplo(test)) {low[dim]++; break;} // found
			test[dim]--;
			if (czyCieplo(test)) {high[dim]--; break;} // found
			if (low[dim]>0) {
				test[dim]--;
				czyCieplo(test);
				test[dim]++;
				if (czyCieplo(test)) {
					low[dim] = high[dim];
				} else {
					high[dim] = low[dim];
				}
			} else {
				test[dim]+=2;
				czyCieplo(test);
				test[dim]--;
				if (czyCieplo(test)) {
					high[dim] = low[dim];
				} else {
					low[dim] = high[dim];
				}
			}
		}

	}
	midpoint(test);
	for (int i = 0; i<D; ++i) {
		czyCieplo(test);
		if (test[i]>0) { 
			test[i]--;
			if (czyCieplo(test)) {high[i]--; low[i]--; break;}
			test[i]++;
		}
		czyCieplo(test);
		if (test[i]<R) {
			test[i]++;
			if (czyCieplo(test)) {high[i]++; low[i]++; break;}
			test[i]--;
		}
	}
	znalazlem(low);
//	znalazlem(high);
	return 0;
}