#include "cielib.h"
int p[509], q[509], question[509];
int d, R;
int goDownOrStay(int *question, int k, int oldPos);
int main()
{
d = podajD();
podajK(); //cza to wogle?
R = podajR();
for (int i = 0; i < d; i++)
{
p[i] = 0;
q[i] = R;
}
int changed = 1;
while (changed)
{
changed = 0;
for (int i = 0; i < d; i++)
{
question[i] = (p[i] + q[i]) / 2;
}
for (int i = 0; i < d; i++)
{
if (p[i] + 2 == q[i])
continue;
changed = 1;
int s = (p[i] + q[i]) / 2;
if (goDownOrStay(question, i, s))
{
q[i] = s + 1;
}
else
{
p[i] = s;
}
}
}
for (int i = 0; i < d; i++)
{
question[i] = (q[i] + p[i]) / 2;
}
for (int i = 0; i < d; i++)
{
int old = question[i];
question[i] = p[i];
czyCieplo(question);
question[i] = old;
int wasP = czyCieplo(question);
question[i] = q[i];
czyCieplo(question);
question[i] = old;
int wasQ = czyCieplo(question);
question[i] = old;
if (!(wasP ^ wasQ))
{
p[i] = old;
}
else if (wasP)
{
p[i] = q[i];
}
}
for (int i = 0; i < d; i++)
{
question[i] = p[i];
}
znalazlem(question);
}
int goDownOrStay(int *question, int k, int oldPos)
{
question[k] = p[k];
czyCieplo(question);
question[k] = q[k];
int wynik = czyCieplo(question);
question[k] = oldPos;
return !wynik;
}
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 | #include "cielib.h" int p[509], q[509], question[509]; int d, R; int goDownOrStay(int *question, int k, int oldPos); int main() { d = podajD(); podajK(); //cza to wogle? R = podajR(); for (int i = 0; i < d; i++) { p[i] = 0; q[i] = R; } int changed = 1; while (changed) { changed = 0; for (int i = 0; i < d; i++) { question[i] = (p[i] + q[i]) / 2; } for (int i = 0; i < d; i++) { if (p[i] + 2 == q[i]) continue; changed = 1; int s = (p[i] + q[i]) / 2; if (goDownOrStay(question, i, s)) { q[i] = s + 1; } else { p[i] = s; } } } for (int i = 0; i < d; i++) { question[i] = (q[i] + p[i]) / 2; } for (int i = 0; i < d; i++) { int old = question[i]; question[i] = p[i]; czyCieplo(question); question[i] = old; int wasP = czyCieplo(question); question[i] = q[i]; czyCieplo(question); question[i] = old; int wasQ = czyCieplo(question); question[i] = old; if (!(wasP ^ wasQ)) { p[i] = old; } else if (wasP) { p[i] = q[i]; } } for (int i = 0; i < d; i++) { question[i] = p[i]; } znalazlem(question); } int goDownOrStay(int *question, int k, int oldPos) { question[k] = p[k]; czyCieplo(question); question[k] = q[k]; int wynik = czyCieplo(question); question[k] = oldPos; return !wynik; } |
English