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
/*
 *  Copyright (C) 2015  Paweł Widera
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details:
 *  http://www.gnu.org/licenses/gpl.html
 */
#include "cielib.h"

#define read_dimensions podajD
#define read_query_limit podajK
#define read_range podajR
#define query czyCieplo
#define send_result znalazlem

#include <vector>
#include <string>
#include <iostream>
using namespace std;


void search(int* position, int d, int lower, int upper) {
	int previous = position[d];
	if (lower == previous) {
		return;
	}

	// left side midpoint
	int midleft = lower + (previous - lower) / 2;
	position[d] = midleft;
	//cout << "pos " << position[d] << endl;
	if (query(position)) {
		//cout << "LEFT " << lower << " " << midleft << " " << previous << endl;
		search(position, d, lower, previous);
	} else {
		// right side midpoint
		int midright = previous + 1 + (upper - previous - 1) / 2;
		position[d] = midright;
		//cout << "pos " << position[d] << endl;
		if (query(position)) {
			//cout << "RIGHT " << previous + 1 << " " << midright << " " << upper << endl;
			search(position, d, previous + 1, upper);
		} else {
			// between
			//cout << "no winner" << endl;
			position[d] = previous;
			//cout << "pos " << position[d] << endl;
			//query(position);
			search(position, d, midleft + 1, midright - 1);
		}
	}

}

int main() {
	int range = read_range();
	int dimensions = read_dimensions();
	int position[dimensions];

	for (int d = 0; d < dimensions; ++d) {
		position[d] = int(range / 2);
	}

	for (int d = 0; d < dimensions; ++d) {
		query(position);
		search(position, d, 0, range);
	}

	send_result(position);
	return 0;
}