#import "cielib.h" // #import <iostream> #import <queue> using namespace std; int main() { int d = podajD(); int r = podajR(); int pos[500]; int min[500]; int max[500]; bool changed[500]; queue<int> q; for (int i = 0; i < d; i++) { pos[i] = 0; min[i] = 0; max[i] = r; changed[i] = false; q.push(i); } while(!q.empty()) { int dim = q.front(); q.pop(); while (min[dim] < max[dim]) { // if (changed[dim]) { // max[dim]++; // changed[dim] = false; // } int prev = pos[dim]; // cout << "dim: " << dim << " min: " << min[dim] << " max: " << max[dim] << " (" << max[dim] - min[dim] << ")" << endl; // int p1 = min[dim] + (max[dim] - min[dim]) / 4; // int p2 = max[dim] - (max[dim] - min[dim]) / 4; if (min[dim] != pos[dim]) { pos[dim] = min[dim]; // cout << "test1: " << pos[dim] << endl; czyCieplo(pos); } pos[dim] = max[dim]; // cout << "test2: " << pos[dim] << endl; if (czyCieplo(pos)) { min[dim] = min[dim] + (max[dim] - min[dim]) / 2 + 1; continue; } pos[dim] = min[dim]; // cout << "test3: " << pos[dim] << endl; if (czyCieplo(pos)) { max[dim] = min[dim] + (max[dim] - min[dim]) / 2; continue; } if ((max[dim] - min[dim]) % 2 == 0) { pos[dim] = min[dim] + (max[dim] - min[dim]) / 2; // cout << "test4: " << pos[dim] << endl; if (czyCieplo(pos)) { min[dim] = max[dim] = pos[dim]; continue; } } if (min[dim] < r) pos[dim] = min[dim] + 1; else if (max[dim] > 0) pos[dim] = max[dim] - 1; if (max[dim] - min[dim] == 2) { if (min[dim] > 0) min[dim]--; else if (max[dim] < r) max[dim]++; } // if (max[dim] > min[dim]) { // max[dim]--; // changed[dim] = true; // } // cout << "break" << endl; q.push(dim); break; // cout << "max: " << max << " min: " << min << endl; } } znalazlem(pos); return 0; }
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 | #import "cielib.h" // #import <iostream> #import <queue> using namespace std; int main() { int d = podajD(); int r = podajR(); int pos[500]; int min[500]; int max[500]; bool changed[500]; queue<int> q; for (int i = 0; i < d; i++) { pos[i] = 0; min[i] = 0; max[i] = r; changed[i] = false; q.push(i); } while(!q.empty()) { int dim = q.front(); q.pop(); while (min[dim] < max[dim]) { // if (changed[dim]) { // max[dim]++; // changed[dim] = false; // } int prev = pos[dim]; // cout << "dim: " << dim << " min: " << min[dim] << " max: " << max[dim] << " (" << max[dim] - min[dim] << ")" << endl; // int p1 = min[dim] + (max[dim] - min[dim]) / 4; // int p2 = max[dim] - (max[dim] - min[dim]) / 4; if (min[dim] != pos[dim]) { pos[dim] = min[dim]; // cout << "test1: " << pos[dim] << endl; czyCieplo(pos); } pos[dim] = max[dim]; // cout << "test2: " << pos[dim] << endl; if (czyCieplo(pos)) { min[dim] = min[dim] + (max[dim] - min[dim]) / 2 + 1; continue; } pos[dim] = min[dim]; // cout << "test3: " << pos[dim] << endl; if (czyCieplo(pos)) { max[dim] = min[dim] + (max[dim] - min[dim]) / 2; continue; } if ((max[dim] - min[dim]) % 2 == 0) { pos[dim] = min[dim] + (max[dim] - min[dim]) / 2; // cout << "test4: " << pos[dim] << endl; if (czyCieplo(pos)) { min[dim] = max[dim] = pos[dim]; continue; } } if (min[dim] < r) pos[dim] = min[dim] + 1; else if (max[dim] > 0) pos[dim] = max[dim] - 1; if (max[dim] - min[dim] == 2) { if (min[dim] > 0) min[dim]--; else if (max[dim] < r) max[dim]++; } // if (max[dim] > min[dim]) { // max[dim]--; // changed[dim] = true; // } // cout << "break" << endl; q.push(dim); break; // cout << "max: " << max << " min: " << min << endl; } } znalazlem(pos); return 0; } |