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
#include <iostream>
#include <vector>
#include "cielib.h"
using namespace std;

int main()
{
  int d = podajD();
  int r = podajR();
  vector <int> p, k;
  p.resize(d,0);
  k.resize(d,r);
  int sr [d];
  for (int i = 0; i < d; i++)
    sr[i] = r/2;
  int dl = r;
  while (dl > 2)
  {
    for (int i = 0; i < d; i++)
    {
      if (k[i] - p[i] < dl)
        continue;
      sr[i] = p[i];
      czyCieplo(sr);
      sr[i] = k[i];
      if(czyCieplo(sr)) {
        p[i] = p[i]+k[i];
        p[i] = (p[i]+(p[i] %2))/2;
        if(k[i] - p[i] == 1)
          p[i] --;
        sr[i] = (p[i]+k[i])/2;
      }
      else {
        sr[i] = p[i];
        if (czyCieplo(sr)) {
          k[i] = (p[i]+k[i])/2;
          if(k[i]-p[i] == 1)
            k[i] ++;
          sr[i] = (p[i]+k[i])/2;
        }
        else {
          sr[i] = (p[i]+k[i])/2;
          k[i] = sr[i] + 1;
          p[i] = sr[i] - 1;
        }
      }
    }
    if (dl == 3)
      dl = 2;
    else
      dl /= 2;
  }
  for (int i = 0; i < d; i++)
  {
    if (k[i] == p[i])
      continue;
    sr[i] = p[i];
    czyCieplo(sr);
    sr[i] = k[i];
    if(czyCieplo(sr)){
      p[i] = k[i];
    }
    else{
      sr[i] = p[i];
      if(czyCieplo(sr))
        k[i] = p[i];
    }
    sr[i] = (p[i]+k[i])/2;
  }
  znalazlem(sr);
  return 0;
}