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

using namespace std;

int * vectors_add(int * x, int * y, int * res, int dim)
{
    for(int i=0; i<dim; i++)
        res[i] = x[i] + y[i];
    return res;
}

int * vectors_add_scaled(int * x, int * y, int * res, int scale, int dim)
{
    for(int i=0; i<dim; i++)
        res[i] = x[i] + scale*y[i];
    return res;
}

void vectors_assign(int * dest, int * src, int dim)
{
    for(int i=0; i<dim; i++)
        dest[i] = src[i];
}

void print(int * x, int dim)
{
    for(int i=0; i<dim; i++)
        cout<<x[i]<<" ";
    cout<<endl;
}

int find_the_largest(int * start, int * dir, int dim, int r)
{
    int max = 0;
    for(int i = 0; i < dim; i++)
    {
        if(start[i] > max && dir[i] > 0)
        {
            max = start[i];
        }
    }
    return (r-max);
}

int find_the_largest_diff(int * start, int * end, int * dir, int dim, int r)
{
    int max = 0;
    for(int i = 0; i < dim; i++)
    {
        if(end[i] - start[i] > max && dir[i] > 0)
        {
            max = end[i] - start[i];
        }
    }
    return (max);
}

int main() {

    int d = podajD();
    int k = podajK();
    int r = podajR();

    int start[d];
    int jed[d];
    int op[d];
    int dir[d];
    list<int> directions;
    list<int> dirs_to_remove;
    int basic_dir = 1;
    for(int i=0; i<d; i++)
    {
        start[i] = 0;
        jed[i]   = 1;
        dir[i]   = 0;
        directions.push_back(i);
    }
    czyCieplo(start);

    if( !czyCieplo(vectors_add(start, jed, op, d)) )
    {
        for(int i=0; i<d; i++)
        {
            start[i] = r;
            jed[i]   = -1;
        }
        basic_dir = -1;
    }

    while(!directions.empty())
    {
        //Find directions
        list<int>::const_iterator iterator;
        for (iterator = directions.begin(); iterator != directions.end(); ++iterator) {
            czyCieplo(start);
            jed[*iterator] = 0;
            if( !czyCieplo(vectors_add(start, jed, op, d)) )
            {
                dirs_to_remove.push_back(*iterator);
                dir[*iterator] = basic_dir;
            }
            jed[*iterator] = basic_dir;
        }
        
        for (iterator = dirs_to_remove.begin(); iterator != dirs_to_remove.end(); ++iterator) {
            directions.remove(*iterator);
        }
        dirs_to_remove.clear();

        //Go there
        czyCieplo(start);
        while(czyCieplo(vectors_add(start, dir, op, d)))
        {
            vectors_assign(start, op, d);
        }
    }

    znalazlem(start);
}