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
110
111
112
//#define dbg if (1)
//#include <cstdio>
#include "cielib.h"

int* current_starting_points;
int* new_starting_points;
int* final_position;

void set_tabs(int d) {
  for (int i = 0; i < d; i++) {
    current_starting_points[i] = 0;
    final_position[i] = 0;
    new_starting_points[i] = 0;
  }
}

void reduce_r(int* current_r, int dims) {
  int* asking_position = new int[dims];
  int min_val, max_val;
  bool result;
  // dbg printf("Trying to reduce: current pos: ");
  for (int i = 0; i < dims; i++) {
    asking_position[i] = current_starting_points[i] + (*current_r / 2);

    // if ((*current_r) % 2 == 1) asking_position[i] += 1;
    // dbg printf("%d ", current_starting_points[i]);
  }
  // dbg printf("\n, min_val: %d, max_val: %d, current_r: %d\n", min_val,
  // max_val,
  //           *current_r);
  for (int i = 0; i < dims; i++) {
    /// sprawdzam w tej chwili wymiar i-ty
    min_val = current_starting_points[i];
    max_val = current_starting_points[i] + *current_r;
    asking_position[i] = min_val;  /// punkt referencyjny
    result = czyCieplo(asking_position);
    asking_position[i] = max_val;
    // dbg printf("minval: %d, maxval: %d\n", min_val, max_val);
    if (czyCieplo(asking_position)) {
      new_starting_points[i] = current_starting_points[i] + (*current_r / 2);
    }
    asking_position[i] = current_starting_points[i] + (*current_r / 2);
  }
  for (int i = 0; i < dims; i++) {
    current_starting_points[i] = new_starting_points[i];
  }
  if ((*current_r) % 2 == 1) (*current_r)++;

  *current_r = *current_r / 2;
  delete[] asking_position;
  return;
}

void get_final_position(int dims, int max_r) {
  int* reference_point = new int[dims];
  int* guess_coord_0 = new int[dims];
  int* guess_coord_2 = new int[dims];
  bool result;
  // dbg printf("reference point is: ");
  for (int i = 0; i < dims; i++) {
    reference_point[i] = current_starting_points[i] + 1;
    guess_coord_0[i] = reference_point[i];
    guess_coord_2[i] = reference_point[i];
    // dbg printf("%d ", reference_point[i]);
  }
  // dbg printf("\n, max_r: %d\n", max_r);

  for (int i = 0; i < dims; i++) {
    guess_coord_0[i] -= 1;
    guess_coord_2[i] += 1;

    czyCieplo(guess_coord_0);
    if (czyCieplo(guess_coord_2)) {
      final_position[i] = guess_coord_2[i];
    } else if (czyCieplo(guess_coord_0)) {
      final_position[i] = guess_coord_0[i];
    } else {
      final_position[i] = reference_point[i];
    }
    guess_coord_0[i] += 1;
    guess_coord_2[i] -= 1;
  }
  delete[] reference_point;
  delete[] guess_coord_0;
  delete[] guess_coord_2;
}

int main() {
  int r, d, k, starting_r;
  d = podajD();
  k = podajK();
  r = podajR();
  current_starting_points = new int[d];
  final_position = new int[d];
  new_starting_points = new int[d];
  set_tabs(d);
  starting_r = r;

  while (r > 2) {
    reduce_r(&r, d);
  }

  /// r jest teraz 2 - ogarnij koncowa pozycje
  get_final_position(d, starting_r);
  // dbg printf("guessing: (");
  // dbg for (int i = 0; i < d; i++) { printf("%d ", final_position[i]); }
  // dbg printf(")\n");
  znalazlem(final_position);
  delete[] current_starting_points;
  delete[] final_position;
  delete[] new_starting_points;
}