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

#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))

int main() {
  int d=podajD();
  int a[d]; //min
  int b[d]; //max
  int t[d]; //temp
  int r = podajR();
  int i,odp,j=0, ex;
  for (i=0;i<d;++i) {
    a[i]=0;
    b[i]=r;
  }
  
  while (j++<33) {
    for (i=0;i<d;++i) {
      t[i] = (b[i]+a[i])/2;
    }
    for (i=0;i<d;++i) {
      if (a[i]==b[i]) continue;
      ex = MIN(a[i], r-b[i]);
      t[i]=a[i]-ex;
      czyCieplo(t); //ustaw pozycje
      t[i]=b[i]+ex;
      odp = czyCieplo(t);
      if (odp==1) { //jest blizej b[i]
	a[i]=(a[i]+b[i])/2 + 1; // +1 ?
	t[i] = (b[i]+a[i])/2;
	//printf("a i=%d a[i]=%d b[i]=%d t[i]=%d\n",i,a[i],b[i],t[i]);
      }
      else {
	t[i]=a[i]-ex;
	odp = czyCieplo(t);
	if (odp==1) { //jest blizej b[i]
	  b[i]=(a[i]+b[i])/2;
	  t[i] = (b[i]+a[i])/2;
	  //printf("b i=%d a[i]=%d b[i]=%d t[i]=%d\n",i,a[i],b[i],t[i]);
	}
	else {
	  a[i]=b[i]=(a[i]+b[i])/2;
	  t[i] = (b[i]+a[i])/2;
	  //printf("a==b i=%d a[i]=%d b[i]=%d t[i]=%d\n",i,a[i],b[i],t[i]);
	}
      }
    }
  }
  /*
  for (i=0;i<d;++i) {
    printf("%d ", a[i]);
  }
  printf("\n");
  for (i=0;i<d;++i) {
    printf("%d ", b[i]);
  }
  */
  znalazlem(a);
  
  
  return 0;
}