#include "cielib.h" int d, r, len, saver; int act_pos[507]; int min_pos[507], max_pos[507]; bool done = false; bool q1, q2; int main() { d = podajD(); r = podajR(); for(int i = 0; i < d; ++i) max_pos[i] = r; int twos = 0, twos_now; while(!done) { for(int i = 0; i < d; ++i){ act_pos[i] = (min_pos[i] + max_pos[i])/2; } twos_now = 0; for(int i = 0; i < d; ++i){ if(max_pos[i] == min_pos[i]){ twos_now++; continue; } len = max_pos[i] - min_pos[i] + 1; if(len == 2){ twos_now++; if(twos == d){ if(max_pos[i] == r){ act_pos[i] = min_pos[i]-1; czyCieplo(act_pos); act_pos[i] = max_pos[i]; q1 = czyCieplo(act_pos); if(q1) min_pos[i] = max_pos[i]; else max_pos[i] = min_pos[i]; } else{ act_pos[i] = max_pos[i]+1; czyCieplo(act_pos); act_pos[i] = min_pos[i]; q1 = czyCieplo(act_pos); if(!q1) min_pos[i] = max_pos[i]; else max_pos[i] = min_pos[i]; } } continue; } saver = act_pos[i]; act_pos[i] = min_pos[i]; czyCieplo(act_pos); act_pos[i] = max_pos[i]; q1 = czyCieplo(act_pos); act_pos[i] = min_pos[i]; q2 = czyCieplo(act_pos); if(!q1 && !q2){ min_pos[i] = min_pos[i] + (len-1)/2; max_pos[i] = max_pos[i] - (len-1)/2; } else if(q1) min_pos[i] = min_pos[i] + (len+1)/2; else max_pos[i] = max_pos[i] - (len+1)/2; act_pos[i] = saver; len = max_pos[i] - min_pos[i] + 1; if(len <= 2) twos_now++; } done = true; int nd = 0; for(int i = 0; i < d; ++i){ if(min_pos[i] != max_pos[i]){ done = false; nd++; } } twos = twos_now; } znalazlem(min_pos); }
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 | #include "cielib.h" int d, r, len, saver; int act_pos[507]; int min_pos[507], max_pos[507]; bool done = false; bool q1, q2; int main() { d = podajD(); r = podajR(); for(int i = 0; i < d; ++i) max_pos[i] = r; int twos = 0, twos_now; while(!done) { for(int i = 0; i < d; ++i){ act_pos[i] = (min_pos[i] + max_pos[i])/2; } twos_now = 0; for(int i = 0; i < d; ++i){ if(max_pos[i] == min_pos[i]){ twos_now++; continue; } len = max_pos[i] - min_pos[i] + 1; if(len == 2){ twos_now++; if(twos == d){ if(max_pos[i] == r){ act_pos[i] = min_pos[i]-1; czyCieplo(act_pos); act_pos[i] = max_pos[i]; q1 = czyCieplo(act_pos); if(q1) min_pos[i] = max_pos[i]; else max_pos[i] = min_pos[i]; } else{ act_pos[i] = max_pos[i]+1; czyCieplo(act_pos); act_pos[i] = min_pos[i]; q1 = czyCieplo(act_pos); if(!q1) min_pos[i] = max_pos[i]; else max_pos[i] = min_pos[i]; } } continue; } saver = act_pos[i]; act_pos[i] = min_pos[i]; czyCieplo(act_pos); act_pos[i] = max_pos[i]; q1 = czyCieplo(act_pos); act_pos[i] = min_pos[i]; q2 = czyCieplo(act_pos); if(!q1 && !q2){ min_pos[i] = min_pos[i] + (len-1)/2; max_pos[i] = max_pos[i] - (len-1)/2; } else if(q1) min_pos[i] = min_pos[i] + (len+1)/2; else max_pos[i] = max_pos[i] - (len+1)/2; act_pos[i] = saver; len = max_pos[i] - min_pos[i] + 1; if(len <= 2) twos_now++; } done = true; int nd = 0; for(int i = 0; i < d; ++i){ if(min_pos[i] != max_pos[i]){ done = false; nd++; } } twos = twos_now; } znalazlem(min_pos); } |