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
// Karol Kosinski
#include "cielib.h"
//#include <cstdio>
#define FR(i,a,b) for(int i=(a);i<(b);++i)
//#define DEBUG(x...) printf(x)
#define DEBUG(x...)
using namespace std;

const int DX = 501;
int Dim[DX], D_min[DX], D_max[DX];
int d, k, r, val;

int max_diff()
{
        int res = 0, dres = D_max[0] - D_min[0];
        FR(i,1,d)
        {
                int aux = D_max[i] - D_min[i];
                if (dres < aux)
                {
                        res = i;
                        dres = aux;
                }
        }
        return res;
}

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

        FR(i,0,d)
        {
                D_min[i] = 0;
                D_max[i] = r;
        }

        int ind = max_diff();
        int diff = D_max[ind] - D_min[ind];
        DEBUG("+ [%d] D_max(%d) - D_min(%d) = %d\n",
                        ind, D_max[ind], D_min[ind], diff);

        while (diff != 0)
        {
                FR(i,0,d)
                        Dim[i] = (D_max[i] + D_min[i]) / 2;

                Dim[ind] = D_min[ind];
                czyCieplo(Dim);
                Dim[ind] = D_max[ind];
                int hot = czyCieplo(Dim);

                if (diff == 2)
                {
                        if (hot)
                                D_min[ind] += diff;
                        else
                        {
                                Dim[ind] = D_min[ind];
                                if (czyCieplo(Dim))
                                        D_max[ind] -= diff;
                                else
                                {
                                        ++D_min[ind];
                                        --D_max[ind];
                                }
                        }
                }
                else if (diff == 3 or diff == 4)
                {
                        if (hot)
                                D_min[ind] += diff / 2;
                        else
                                D_max[ind] -= diff / 2;
                }
                else
                {
                        if (hot)
                                D_min[ind] += diff / 2 + 1;
                        else
                                D_max[ind] -= diff / 2;
                }
                DEBUG("- [%d] D_max(%d) - D_min(%d) = %d\n",
                                ind, D_max[ind], D_min[ind], D_max[ind] - D_min[ind]);
                ind = max_diff();
                diff = D_max[ind] - D_min[ind];
                DEBUG("+ [%d] D_max(%d) - D_min(%d) = %d\n",
                                ind, D_max[ind], D_min[ind], diff);
        }
        znalazlem(D_min);
}