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
113
114
115
116
117
118
119
120
121
122
#include <utility>
#include "cielib.h"

int main()
{
    int d = podajD();
    int r = podajR();

    std::pair<int, int> *range = new std::pair<int, int>[d];
    std::pair<int, int> *newRange = new std::pair<int, int>[d];

    for( int i = 0; i < d; ++i )
        range[i] = { 0, r };

    int side = r+1;
    int *point = new int[d];

    if( side % 2 == 0 )
    {
        side /= 2;
        for( int D = 0; D < d; ++D )
        {
            for(int i=0; i<d; ++i)
                if( i != D )
                    point[i] = ( range[i].first + range[i].second ) / 2;

            point[D] = range[D].first;
            czyCieplo( point );

            for( int i = 0; i < d; ++i )
                if( i != D )
                    point[i] = ( range[i].first + range[i].second + 1 ) / 2;

            point[D] = range[D].second;
            bool pInRightHalf = czyCieplo( point );

            for(int i=0; i<d; ++i)
                if( i != D )
                    point[i] = ( range[i].first + range[i].second ) / 2;
            point[D] = range[D].first;
            bool pInLeftHalf = czyCieplo( point );

            int mid = ( range[D].first + range[D].second ) / 2;

            if( side % 2 == 0 )
            {
                if( pInLeftHalf )
                    newRange[D] = { range[D].first, mid + 1 };
                else if( pInRightHalf )
                    newRange[D] = { mid, range[D].second };
                else
                    newRange[D] = { mid - side/2, mid + side/2 };
            }
            else
            {
                if( pInLeftHalf )
                    newRange[D] = { range[D].first, mid };
                else if( pInRightHalf )
                    newRange[D] = { mid + 1, range[D].second };
                else
                    newRange[D] = { mid - side/2, mid + side/2 };
            }
        }

        for( int i = 0; i < d; ++i )
            range[i] = newRange[i];
        if( side % 2 == 0 )
            ++side;
    }

    while( side > 2 )
    {
        side /= 2;
        for( int D = 0; D < d; ++D )
        {
            for( int i = 0; i < d; ++i )
                if( i != D )
                    point[i] = ( range[i].first + range[i].second ) / 2;

            point[D] = range[D].first;
            czyCieplo( point );

            point[D] = range[D].second;
            bool pInRightHalf = czyCieplo( point );

            point[D] = range[D].first;
            bool pInLeftHalf = czyCieplo( point );

            int mid = ( range[D].first + range[D].second ) / 2;

            if( side % 2 == 1 )
            {
                if( pInLeftHalf )
                    newRange[D] = { range[D].first, mid - 1 };
                else if( pInRightHalf )
                    newRange[D] = { mid + 1, range[D].second };
                else
                    newRange[D] = { mid - side/2, mid + side/2 };
            }
            else
            {
                if( pInLeftHalf )
                    newRange[D] = { range[D].first, mid };
                else if( pInRightHalf )
                    newRange[D] = { mid, range[D].second };
                else
                    newRange[D] = { mid - side/2, mid + side/2 };
            }
        }

        for( int i = 0; i < d; ++i )
            range[i] = newRange[i];
        if( side % 2 == 0 )
            ++side;
    }

    for( int i = 0; i < d; ++i )
        point[i] = range[i].first;
    znalazlem( point );

    return 0;
}