#include "cielib.h" #include <iostream> int lowlimit[500] = {}; int highlimit[500]; int curpos[500]; int midp(int i){ return lowlimit[i] + (highlimit[i] - lowlimit[i])/2; } int main() { int d = podajD(); int r = podajR(); int range = r; for(int i = 0; i < d; i++){ highlimit[i] = r; } while(range / 2){ for(int i = 0; i < d; ++i) { curpos[i] = midp(i); } for(int i = 0; i < d; ++i) { curpos[i] = highlimit[i]; czyCieplo(curpos); curpos[i] = lowlimit[i]; bool res = czyCieplo(curpos); curpos[i] = midp(i); if(res){ highlimit[i] = midp(i); } else { lowlimit[i] = midp(i); } } range /= 2; } for(int i = 0; i < d; ++i) { if(highlimit[i] - lowlimit[i] < 2){ if(lowlimit[i]){ lowlimit[i]--; } else { highlimit[i]++; } } curpos[i] = lowlimit[i] + 1; } for(int i = 0; i < d; ++i) { curpos[i] = highlimit[i]; czyCieplo(curpos); curpos[i] = lowlimit[i]; bool res1 = czyCieplo(curpos); curpos[i] = highlimit[i]; bool res2 = czyCieplo(curpos); if(!res1 and !res2){ curpos[i] = lowlimit[i] + 1; } else if(res1){ curpos[i] = lowlimit[i]; } else { curpos[i] = lowlimit[i] + 2; } } range /= 2; znalazlem(curpos); }
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 | #include "cielib.h" #include <iostream> int lowlimit[500] = {}; int highlimit[500]; int curpos[500]; int midp(int i){ return lowlimit[i] + (highlimit[i] - lowlimit[i])/2; } int main() { int d = podajD(); int r = podajR(); int range = r; for(int i = 0; i < d; i++){ highlimit[i] = r; } while(range / 2){ for(int i = 0; i < d; ++i) { curpos[i] = midp(i); } for(int i = 0; i < d; ++i) { curpos[i] = highlimit[i]; czyCieplo(curpos); curpos[i] = lowlimit[i]; bool res = czyCieplo(curpos); curpos[i] = midp(i); if(res){ highlimit[i] = midp(i); } else { lowlimit[i] = midp(i); } } range /= 2; } for(int i = 0; i < d; ++i) { if(highlimit[i] - lowlimit[i] < 2){ if(lowlimit[i]){ lowlimit[i]--; } else { highlimit[i]++; } } curpos[i] = lowlimit[i] + 1; } for(int i = 0; i < d; ++i) { curpos[i] = highlimit[i]; czyCieplo(curpos); curpos[i] = lowlimit[i]; bool res1 = czyCieplo(curpos); curpos[i] = highlimit[i]; bool res2 = czyCieplo(curpos); if(!res1 and !res2){ curpos[i] = lowlimit[i] + 1; } else if(res1){ curpos[i] = lowlimit[i]; } else { curpos[i] = lowlimit[i] + 2; } } range /= 2; znalazlem(curpos); } |