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
#include <vector>

#include "cielib.h"

int dim;
int length;

std::vector<std::pair<int, int>> ranges;
std::vector<int> currentPos;

int leftMid(int l, int r) {
	return (l + r) / 2;
}

int rightMid(int l, int r) {
	return (l + r + 1) / 2;
}

void iter() {
	for (int i = 0; i < dim; ++i) {
		int l = ranges[i].first;
		int r = ranges[i].second;

		currentPos[i] = l;
		czyCieplo(currentPos.data());
		currentPos[i] = r;
		int isRightEndWarmer = czyCieplo(currentPos.data());

		if (isRightEndWarmer) {
			ranges[i] = std::make_pair(leftMid(l, r), ranges[i].second);
		} else {
			ranges[i] = std::make_pair(ranges[i].first, rightMid(l, r));
		}
		currentPos[i] = leftMid(ranges[i].first, ranges[i].second);
	}
}

void length_2_case() {
	for (int i = 0; i < dim; ++i) {
		int l = ranges[i].first;
		int r = ranges[i].second;

		currentPos[i] = l;
		czyCieplo(currentPos.data());
		currentPos[i] = r;
		int isRightEndWarmer = czyCieplo(currentPos.data());
		currentPos[i] = l;
		int isLeftEndWarmer = czyCieplo(currentPos.data());

		if (isLeftEndWarmer) {
			currentPos[i] = l;
		} else if (isRightEndWarmer) {
			currentPos[i] = r;
		} else {
			currentPos[i] = (l + r) / 2;
		}
	}
}

int main() {
	dim = podajD();
	length = podajR();

	for (int i = 0; i < dim; ++i) {
		ranges.push_back(std::make_pair(0, length));
		currentPos.push_back(leftMid(0, length));
	}

	while (ranges[0].second - ranges[0].first > 2) {
		iter();
	}
	length_2_case();
	znalazlem(currentPos.data());
}