#include "cielib.h" #include <iostream> #include <cmath> using namespace std; void doubleBinSearch(){ int low = 0; int high = podajR() - 1; int mid; int r[2]; while(low < high){ mid = (low + high)/2; r[0] = low; r[1] = low; int low_r = czyCieplo(r); r[0] = high; r[1] = high; int high_r = czyCieplo(r); if(low == high){ break; } if(high_r == 1){ low = mid + 1; } else { high = mid; } } int x; int y; if(low != podajR() -1){ r[0] = low+1; r[1] = low+1; czyCieplo(r); r[0] = low; r[1] = low; //unparity if(czyCieplo(r) == 0){ x = low; y = low+1; } else { x = low; y = low; } } else { x = low; y = low; } while(x != 0 && y != podajR() -1){ x--; y++; } //COPYPASTA high = 0; while(((x+high) != podajR() -1) && (y-high) != 0){ high++; } low = 0; mid; r[2]; while(low < high){ mid = (low + high)/2; r[0] = x + low; r[1] = y - low; int low_r = czyCieplo(r); r[0] = x + high; r[1] = y - high; int high_r = czyCieplo(r); if(high_r == 1){ low = mid + 1; } else { high = mid; } } //cout << x + low << " " << y - low << endl; r[0] = x+low; r[1] = y-low; znalazlem(r); } //normal void normalBinSearch(){ int low = 0; int high = podajR() - 1; int mid; int r[1]; while(low < high){ mid = (low + high)/2; r[0] = low; int low_r = czyCieplo(r); r[0] = high; int high_r = czyCieplo(r); if(low == high){ break; } if(high_r == 1){ low = mid + 1; } else { high = mid; } } r[0] = low; znalazlem(r); } int main() { int dimensions = podajD(); if(dimensions == 1){ normalBinSearch(); } else if(dimensions == 2){ doubleBinSearch(); } else { int r[dimensions]; for(int x=0; x<dimensions; x++){ r[x]=0; } znalazlem(r); } }
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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | #include "cielib.h" #include <iostream> #include <cmath> using namespace std; void doubleBinSearch(){ int low = 0; int high = podajR() - 1; int mid; int r[2]; while(low < high){ mid = (low + high)/2; r[0] = low; r[1] = low; int low_r = czyCieplo(r); r[0] = high; r[1] = high; int high_r = czyCieplo(r); if(low == high){ break; } if(high_r == 1){ low = mid + 1; } else { high = mid; } } int x; int y; if(low != podajR() -1){ r[0] = low+1; r[1] = low+1; czyCieplo(r); r[0] = low; r[1] = low; //unparity if(czyCieplo(r) == 0){ x = low; y = low+1; } else { x = low; y = low; } } else { x = low; y = low; } while(x != 0 && y != podajR() -1){ x--; y++; } //COPYPASTA high = 0; while(((x+high) != podajR() -1) && (y-high) != 0){ high++; } low = 0; mid; r[2]; while(low < high){ mid = (low + high)/2; r[0] = x + low; r[1] = y - low; int low_r = czyCieplo(r); r[0] = x + high; r[1] = y - high; int high_r = czyCieplo(r); if(high_r == 1){ low = mid + 1; } else { high = mid; } } //cout << x + low << " " << y - low << endl; r[0] = x+low; r[1] = y-low; znalazlem(r); } //normal void normalBinSearch(){ int low = 0; int high = podajR() - 1; int mid; int r[1]; while(low < high){ mid = (low + high)/2; r[0] = low; int low_r = czyCieplo(r); r[0] = high; int high_r = czyCieplo(r); if(low == high){ break; } if(high_r == 1){ low = mid + 1; } else { high = mid; } } r[0] = low; znalazlem(r); } int main() { int dimensions = podajD(); if(dimensions == 1){ normalBinSearch(); } else if(dimensions == 2){ doubleBinSearch(); } else { int r[dimensions]; for(int x=0; x<dimensions; x++){ r[x]=0; } znalazlem(r); } } |