#include "cielib.h" #include <memory.h> int* tabCenter; int* tabLeft; int* tabRight; int* tabSize; int dimensions = 0; int rsize = 0; int currsize = 0; int test = 0; void lastFind() { for(int coord = 0; coord < dimensions; ++coord) { if(tabSize[coord] < currsize) continue; tabCenter[coord] = tabRight[coord]; czyCieplo(tabCenter); tabCenter[coord] = tabLeft[coord]; bool bFirst = czyCieplo(tabCenter); tabCenter[coord] = tabRight[coord]; bool bSecond = czyCieplo(tabCenter); tabSize[coord] = 0; if(bFirst && !bSecond) { tabCenter[coord] = tabLeft[coord]; } else if(bSecond) { tabCenter[coord] = tabRight[coord]; } else { tabCenter[coord] = tabLeft[coord] + 1; } } } void cutSpace(int coord) { tabCenter[coord] = tabRight[coord]; czyCieplo(tabCenter); tabCenter[coord] = tabLeft[coord]; if(czyCieplo(tabCenter)) { tabRight[coord] = (tabRight[coord] + tabLeft[coord]) / 2; tabCenter[coord] = (tabRight[coord] + tabLeft[coord]) / 2; tabSize[coord] = tabRight[coord] - tabLeft[coord]; } else { tabCenter[coord] = tabRight[coord]; if(czyCieplo(tabCenter)) { tabLeft[coord] = (tabRight[coord] + tabLeft[coord]) / 2; tabCenter[coord] = (tabRight[coord] + tabLeft[coord]) / 2; tabSize[coord] = tabRight[coord] - tabLeft[coord]; } //czyCieplo else { tabLeft[coord] = (tabRight[coord] + tabLeft[coord]) / 2; tabRight[coord] = tabLeft[coord]; tabCenter[coord] = tabLeft[coord]; tabSize[coord] = 0; } } } void makeEven(int coord) { tabCenter[coord] = tabRight[coord]; czyCieplo(tabCenter); tabCenter[coord] = tabLeft[coord]; if(czyCieplo(tabCenter)) { if(tabSize[coord] > 3) { tabRight[coord] = (tabRight[coord] + tabLeft[coord]) / 2; tabCenter[coord] = (tabRight[coord] + tabLeft[coord]) / 2; tabSize[coord] = tabRight[coord] - tabLeft[coord]; } else //size == 3 { tabRight[coord] = tabLeft[coord] + 2; tabCenter[coord] = tabLeft[coord] + 1; tabSize[coord] = 2; } } else { tabCenter[coord] = tabRight[coord]; if(czyCieplo(tabCenter)) { if(tabSize[coord] > 3) { tabLeft[coord] = (tabRight[coord] + tabLeft[coord]) / 2 + 1; tabCenter[coord] = (tabRight[coord] + tabLeft[coord]) / 2; tabSize[coord] = tabRight[coord] - tabLeft[coord]; } else // size == 3 { tabLeft[coord] += 1; tabCenter[coord] = tabLeft[coord] + 1; tabSize[coord] = 2; } } //czyCieplo else { if(tabSize[coord] > 3) { tabLeft[coord] = (tabLeft[coord] + tabRight[coord]) / 2; tabRight[coord] = tabLeft[coord] + 2; tabCenter[coord] = tabLeft[coord] + 1; tabSize[coord] = 2; } else // size = 3 { tabRight[coord] -= 1; tabCenter[coord] = tabLeft[coord] + 1; tabSize[coord] = 2; } } } } void process() { for(int coord = 0; coord < dimensions; ++coord) { if(tabSize[coord] < currsize) continue; if(currsize & 1) makeEven(coord); else cutSpace(coord); } currsize /= 2; } int main() { dimensions = podajD(); rsize = podajR(); currsize = rsize; tabCenter = new int[dimensions]; tabLeft = new int[dimensions]; tabRight = new int[dimensions]; tabSize = new int[dimensions]; memset(tabLeft, 0, dimensions * sizeof(int)); for(int idx = 0, halb = rsize / 2; idx < dimensions; ++idx) { tabRight[idx] = rsize; tabCenter[idx] = halb; tabSize[idx] = rsize; } while(currsize > 2) process(); lastFind(); znalazlem(tabCenter); }
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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | #include "cielib.h" #include <memory.h> int* tabCenter; int* tabLeft; int* tabRight; int* tabSize; int dimensions = 0; int rsize = 0; int currsize = 0; int test = 0; void lastFind() { for(int coord = 0; coord < dimensions; ++coord) { if(tabSize[coord] < currsize) continue; tabCenter[coord] = tabRight[coord]; czyCieplo(tabCenter); tabCenter[coord] = tabLeft[coord]; bool bFirst = czyCieplo(tabCenter); tabCenter[coord] = tabRight[coord]; bool bSecond = czyCieplo(tabCenter); tabSize[coord] = 0; if(bFirst && !bSecond) { tabCenter[coord] = tabLeft[coord]; } else if(bSecond) { tabCenter[coord] = tabRight[coord]; } else { tabCenter[coord] = tabLeft[coord] + 1; } } } void cutSpace(int coord) { tabCenter[coord] = tabRight[coord]; czyCieplo(tabCenter); tabCenter[coord] = tabLeft[coord]; if(czyCieplo(tabCenter)) { tabRight[coord] = (tabRight[coord] + tabLeft[coord]) / 2; tabCenter[coord] = (tabRight[coord] + tabLeft[coord]) / 2; tabSize[coord] = tabRight[coord] - tabLeft[coord]; } else { tabCenter[coord] = tabRight[coord]; if(czyCieplo(tabCenter)) { tabLeft[coord] = (tabRight[coord] + tabLeft[coord]) / 2; tabCenter[coord] = (tabRight[coord] + tabLeft[coord]) / 2; tabSize[coord] = tabRight[coord] - tabLeft[coord]; } //czyCieplo else { tabLeft[coord] = (tabRight[coord] + tabLeft[coord]) / 2; tabRight[coord] = tabLeft[coord]; tabCenter[coord] = tabLeft[coord]; tabSize[coord] = 0; } } } void makeEven(int coord) { tabCenter[coord] = tabRight[coord]; czyCieplo(tabCenter); tabCenter[coord] = tabLeft[coord]; if(czyCieplo(tabCenter)) { if(tabSize[coord] > 3) { tabRight[coord] = (tabRight[coord] + tabLeft[coord]) / 2; tabCenter[coord] = (tabRight[coord] + tabLeft[coord]) / 2; tabSize[coord] = tabRight[coord] - tabLeft[coord]; } else //size == 3 { tabRight[coord] = tabLeft[coord] + 2; tabCenter[coord] = tabLeft[coord] + 1; tabSize[coord] = 2; } } else { tabCenter[coord] = tabRight[coord]; if(czyCieplo(tabCenter)) { if(tabSize[coord] > 3) { tabLeft[coord] = (tabRight[coord] + tabLeft[coord]) / 2 + 1; tabCenter[coord] = (tabRight[coord] + tabLeft[coord]) / 2; tabSize[coord] = tabRight[coord] - tabLeft[coord]; } else // size == 3 { tabLeft[coord] += 1; tabCenter[coord] = tabLeft[coord] + 1; tabSize[coord] = 2; } } //czyCieplo else { if(tabSize[coord] > 3) { tabLeft[coord] = (tabLeft[coord] + tabRight[coord]) / 2; tabRight[coord] = tabLeft[coord] + 2; tabCenter[coord] = tabLeft[coord] + 1; tabSize[coord] = 2; } else // size = 3 { tabRight[coord] -= 1; tabCenter[coord] = tabLeft[coord] + 1; tabSize[coord] = 2; } } } } void process() { for(int coord = 0; coord < dimensions; ++coord) { if(tabSize[coord] < currsize) continue; if(currsize & 1) makeEven(coord); else cutSpace(coord); } currsize /= 2; } int main() { dimensions = podajD(); rsize = podajR(); currsize = rsize; tabCenter = new int[dimensions]; tabLeft = new int[dimensions]; tabRight = new int[dimensions]; tabSize = new int[dimensions]; memset(tabLeft, 0, dimensions * sizeof(int)); for(int idx = 0, halb = rsize / 2; idx < dimensions; ++idx) { tabRight[idx] = rsize; tabCenter[idx] = halb; tabSize[idx] = rsize; } while(currsize > 2) process(); lastFind(); znalazlem(tabCenter); } |