#include <bits/stdc++.h> #include "cielib.h" using namespace std; typedef long long int64; #define DEBUG(x) cerr << #x << " = " << x << endl; #define REP(x, n) for(__typeof(n) x = 0; x < (n); ++x) #define FOR(x, b, e) for(__typeof(b) x = (b); x != (e); x += 1 - 2 * ((b) > (e))) const int INF = 1000000001; const double EPS = 10e-9; struct FirstInterval { int p, k; }; struct DiagonalCoordinator { int d; vector<int> begin; vector<int> direction; DiagonalCoordinator(int dim, vector<bool>& dir, int point[]) : d(dim), begin(d), direction(d) { REP(x, d) { begin[x] = point[x]; direction[x] = dir[x] ? 1 : -1; } } int getLength(int r) { int l = INF; REP(x, d) { if (direction[x] == 1) { l = min(l, r - begin[x] + 1); } else { l = min(l, begin[x] + 1); } } return l; } void setPosition(int pos, int question[]) { REP(x, d) { question[x] = begin[x] + direction[x] * pos; } } }; struct Solver { int d, k, r, *question; vector<bool> ascending; Solver() { d = podajD(); k = podajK(); r = podajR(); question = new int[d]; ascending = vector<bool>(d); } ~Solver() { delete[] question; } void findCenter() { REP(x, d) { question[x] = (0, r) / 2; } } FirstInterval firstInterval(int i) { int b = question[i]; question[i] = 0; bool low = czyCieplo(question); question[i] = b; bool high = czyCieplo(question); FirstInterval result; if (low || high) { result.p = 0; result.k = b; } else { result.p = b; result.k = r; } return result; } int corner(int i, FirstInterval& interval) { int p = interval.p; int k = interval.k; bool right = (p == 0); if (right) { question[i] = k; } else { question[i] = p; } czyCieplo(question); while (p < k) { int s = (p + k) / 2; if (k - p == 1) { s = right ? p : k; } if (right) { question[i] = s; bool low = czyCieplo(question); question[i] = k; bool high = czyCieplo(question); if (low || high) { p = s + 1; } else { k = s; } } else { question[i] = s; bool low = czyCieplo(question); question[i] = p; bool high = czyCieplo(question); if (low || high) { k = s - 1; } else { p = s; } } } return p; } void solve() { vector<bool> direction(d); if (d > 1) { findCenter(); REP(i, d) { czyCieplo(question); auto interval = firstInterval(i); question[i] = corner(i, interval); } REP(i, d) { if (question[i] == 0) { direction[i] = true; } else { question[i]--; bool low = czyCieplo(question); question[i]++; bool high = czyCieplo(question); direction[i] = low || high; } } } else { direction[0] = 1; question[0] = 0; } DiagonalCoordinator coord(d, direction, question); int p = 0, k = coord.getLength(r) - 1; while (p < k) { int s = (p + k) / 2; coord.setPosition(s, question); czyCieplo(question); coord.setPosition(s + 1, question); bool low = czyCieplo(question); if (low) { p = s + 1; } else { k = s; } } coord.setPosition(p, question); znalazlem(question); } }; #ifndef CATCH_TEST int main() { int d = podajD(); int k = podajK(); int r = podajR(); int question[d]; Solver solver; solver.solve(); return 0; } #endif
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 179 180 181 182 183 184 185 186 | #include <bits/stdc++.h> #include "cielib.h" using namespace std; typedef long long int64; #define DEBUG(x) cerr << #x << " = " << x << endl; #define REP(x, n) for(__typeof(n) x = 0; x < (n); ++x) #define FOR(x, b, e) for(__typeof(b) x = (b); x != (e); x += 1 - 2 * ((b) > (e))) const int INF = 1000000001; const double EPS = 10e-9; struct FirstInterval { int p, k; }; struct DiagonalCoordinator { int d; vector<int> begin; vector<int> direction; DiagonalCoordinator(int dim, vector<bool>& dir, int point[]) : d(dim), begin(d), direction(d) { REP(x, d) { begin[x] = point[x]; direction[x] = dir[x] ? 1 : -1; } } int getLength(int r) { int l = INF; REP(x, d) { if (direction[x] == 1) { l = min(l, r - begin[x] + 1); } else { l = min(l, begin[x] + 1); } } return l; } void setPosition(int pos, int question[]) { REP(x, d) { question[x] = begin[x] + direction[x] * pos; } } }; struct Solver { int d, k, r, *question; vector<bool> ascending; Solver() { d = podajD(); k = podajK(); r = podajR(); question = new int[d]; ascending = vector<bool>(d); } ~Solver() { delete[] question; } void findCenter() { REP(x, d) { question[x] = (0, r) / 2; } } FirstInterval firstInterval(int i) { int b = question[i]; question[i] = 0; bool low = czyCieplo(question); question[i] = b; bool high = czyCieplo(question); FirstInterval result; if (low || high) { result.p = 0; result.k = b; } else { result.p = b; result.k = r; } return result; } int corner(int i, FirstInterval& interval) { int p = interval.p; int k = interval.k; bool right = (p == 0); if (right) { question[i] = k; } else { question[i] = p; } czyCieplo(question); while (p < k) { int s = (p + k) / 2; if (k - p == 1) { s = right ? p : k; } if (right) { question[i] = s; bool low = czyCieplo(question); question[i] = k; bool high = czyCieplo(question); if (low || high) { p = s + 1; } else { k = s; } } else { question[i] = s; bool low = czyCieplo(question); question[i] = p; bool high = czyCieplo(question); if (low || high) { k = s - 1; } else { p = s; } } } return p; } void solve() { vector<bool> direction(d); if (d > 1) { findCenter(); REP(i, d) { czyCieplo(question); auto interval = firstInterval(i); question[i] = corner(i, interval); } REP(i, d) { if (question[i] == 0) { direction[i] = true; } else { question[i]--; bool low = czyCieplo(question); question[i]++; bool high = czyCieplo(question); direction[i] = low || high; } } } else { direction[0] = 1; question[0] = 0; } DiagonalCoordinator coord(d, direction, question); int p = 0, k = coord.getLength(r) - 1; while (p < k) { int s = (p + k) / 2; coord.setPosition(s, question); czyCieplo(question); coord.setPosition(s + 1, question); bool low = czyCieplo(question); if (low) { p = s + 1; } else { k = s; } } coord.setPosition(p, question); znalazlem(question); } }; #ifndef CATCH_TEST int main() { int d = podajD(); int k = podajK(); int r = podajR(); int question[d]; Solver solver; solver.solve(); return 0; } #endif |