//Patryk Kisielewski - PA 2016 - Cieplo-zimno B [CIE] - v2 #include "cielib.h" void findPosioton(int [], int [][2], bool [], int); int main(){ int d = podajD(); int r = podajR(); int arr[d]; int range[d][2]; bool is_top[d]; for(int i = 0; i < d; ++i){ arr[i] = 1; range[i][0] = 0; range[i][1] = r; is_top[i] = false; } findPosioton(arr, range, is_top, d); return 0; } void findPosioton(int arr[], int range[][2], bool is_top[], int d){ if(range[0][1]-range[0][0] < 4){ for(int i = 0; i < d; ++i) arr[i] = range[i][0]; czyCieplo(arr); for(int i = 0; i < d; ++i) arr[i]++; if(czyCieplo(arr)){ for(int i = 0; i < d; ++i) arr[i]++; if(czyCieplo(arr)){ znalazlem(arr); return; } else { for(int i = 0; i < d; ++i) arr[i]--; znalazlem(arr); return; } } else { for(int i = 0; i < d; ++i) arr[i]--; znalazlem(arr); return; } } for(int i = 0; i < d; ++i){ int index = 0; int rindex = 1; if(is_top[i]){ index = 1; rindex = 0; arr[i]++; } else { arr[i]--; } czyCieplo(arr); arr[i] = range[i][rindex]; if(czyCieplo(arr)){ is_top[i] = ~is_top[i]; arr[i]--; } else { arr[i] = range[i][index]+1; } if(is_top[i] == true) range[i][0] = (range[i][0]+range[i][1])/2-1; else range[i][1] = (range[i][0]+range[i][1])/2+1; } findPosioton(arr, range, is_top, d); }
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 | //Patryk Kisielewski - PA 2016 - Cieplo-zimno B [CIE] - v2 #include "cielib.h" void findPosioton(int [], int [][2], bool [], int); int main(){ int d = podajD(); int r = podajR(); int arr[d]; int range[d][2]; bool is_top[d]; for(int i = 0; i < d; ++i){ arr[i] = 1; range[i][0] = 0; range[i][1] = r; is_top[i] = false; } findPosioton(arr, range, is_top, d); return 0; } void findPosioton(int arr[], int range[][2], bool is_top[], int d){ if(range[0][1]-range[0][0] < 4){ for(int i = 0; i < d; ++i) arr[i] = range[i][0]; czyCieplo(arr); for(int i = 0; i < d; ++i) arr[i]++; if(czyCieplo(arr)){ for(int i = 0; i < d; ++i) arr[i]++; if(czyCieplo(arr)){ znalazlem(arr); return; } else { for(int i = 0; i < d; ++i) arr[i]--; znalazlem(arr); return; } } else { for(int i = 0; i < d; ++i) arr[i]--; znalazlem(arr); return; } } for(int i = 0; i < d; ++i){ int index = 0; int rindex = 1; if(is_top[i]){ index = 1; rindex = 0; arr[i]++; } else { arr[i]--; } czyCieplo(arr); arr[i] = range[i][rindex]; if(czyCieplo(arr)){ is_top[i] = ~is_top[i]; arr[i]--; } else { arr[i] = range[i][index]+1; } if(is_top[i] == true) range[i][0] = (range[i][0]+range[i][1])/2-1; else range[i][1] = (range[i][0]+range[i][1])/2+1; } findPosioton(arr, range, is_top, d); } |