// Przemysław Szpakowicz // HEURA #include <bits/stdc++.h> #include "cielib.h" #define FOR(x, a, b) for(x = a; x < b; ++x) const int MaxD = 510; int d, r; int p[MaxD]; int b[MaxD]; int e[MaxD]; void readTest() { d = podajD(); r = podajR(); } void makePreprocessing() { int i; ++r; FOR(i, 0, d) b[i] = 0, e[i] = r, p[i] = (b[i] + e[i]) / 2; r = (r + 1) / 2; } int main() { readTest(); makePreprocessing(); while(r > 0) { r = 0; int i; FOR(i, 0, d) { int diff = e[i] - b[i]; if(diff == 2) { if(b[i] > 0) --b[i]; else ++e[i]; ++diff; } int m = (b[i] + e[i]) / 2; p[i] = b[i]; czyCieplo(p); p[i] = m; bool r1 = czyCieplo(p); p[i] = e[i] - 1; czyCieplo(p); p[i] = m; bool r2 = czyCieplo(p); if(r1 == false && r2 == false) { if(diff == 3) b[i] = m, e[i] = b[i] + 1; else b[i] = b[i] + diff / 4, e[i] = e[i] - diff / 4; if(e[i] <= b[i]) e[i] = b[i] + 1; } else if(r1 && r2 == false) { b[i] = m - 1; if(diff == 3) b[i] = e[i] - 1; } else if(r1 == false && r2) { e[i] = m; if(diff == 3) e[i] = b[i] + 1; } else if(r1 && r2) { if(diff == 3) b[i] = m, e[i] = b[i] + 1; else b[i] = b[i] + diff / 4, e[i] = e[i] - diff / 4; if(e[i] <= b[i]) e[i] = b[i] + 1; } diff = e[i] - b[i]; if(diff == 2) { if(b[i] > 0) --b[i]; else ++e[i]; } p[i] = (b[i] + e[i]) / 2; r = std::max(r, e[i] - b[i]); } if(r == 1) break; r = r / 2; } znalazlem(p); }
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 | // Przemysław Szpakowicz // HEURA #include <bits/stdc++.h> #include "cielib.h" #define FOR(x, a, b) for(x = a; x < b; ++x) const int MaxD = 510; int d, r; int p[MaxD]; int b[MaxD]; int e[MaxD]; void readTest() { d = podajD(); r = podajR(); } void makePreprocessing() { int i; ++r; FOR(i, 0, d) b[i] = 0, e[i] = r, p[i] = (b[i] + e[i]) / 2; r = (r + 1) / 2; } int main() { readTest(); makePreprocessing(); while(r > 0) { r = 0; int i; FOR(i, 0, d) { int diff = e[i] - b[i]; if(diff == 2) { if(b[i] > 0) --b[i]; else ++e[i]; ++diff; } int m = (b[i] + e[i]) / 2; p[i] = b[i]; czyCieplo(p); p[i] = m; bool r1 = czyCieplo(p); p[i] = e[i] - 1; czyCieplo(p); p[i] = m; bool r2 = czyCieplo(p); if(r1 == false && r2 == false) { if(diff == 3) b[i] = m, e[i] = b[i] + 1; else b[i] = b[i] + diff / 4, e[i] = e[i] - diff / 4; if(e[i] <= b[i]) e[i] = b[i] + 1; } else if(r1 && r2 == false) { b[i] = m - 1; if(diff == 3) b[i] = e[i] - 1; } else if(r1 == false && r2) { e[i] = m; if(diff == 3) e[i] = b[i] + 1; } else if(r1 && r2) { if(diff == 3) b[i] = m, e[i] = b[i] + 1; else b[i] = b[i] + diff / 4, e[i] = e[i] - diff / 4; if(e[i] <= b[i]) e[i] = b[i] + 1; } diff = e[i] - b[i]; if(diff == 2) { if(b[i] > 0) --b[i]; else ++e[i]; } p[i] = (b[i] + e[i]) / 2; r = std::max(r, e[i] - b[i]); } if(r == 1) break; r = r / 2; } znalazlem(p); } |