#include "cielib.h" #include <algorithm> #include <utility> #include <vector> using namespace std; using pii = pair<int, int>; int main() { int d = podajD(); int r = podajR(); vector<int> pos(d); vector<pii> res(d, {0, r}); while (1) { auto it = max_element( res.begin(), res.end(), [](pii const& a, pii const& b) { return a.second - a.first < b.second - b.first; }); int delta = it->second - it->first; if (!delta) { break; } int max_d = (delta+1) / 2; for (int i=0; i<d; i++) { pos[i] = (res[i].first + res[i].second) / 2; } int ind = it - res.begin(); pos[ind] = res[ind].first; czyCieplo(pos.data()); pos[ind] = res[ind].second; bool cright = czyCieplo(pos.data()); pos[ind] = res[ind].first; bool cleft = czyCieplo(pos.data()); if (cright) { if (delta == 2) { res[ind].first = res[ind].second; } else { res[ind].first = res[ind].second - max_d; } } else if (cleft) { if (delta == 2) { res[ind].second = res[ind].first; } else { res[ind].second = res[ind].first + max_d; } } else { bool nope = res[ind].first % 2 != res[ind].second % 2; res[ind].first = res[ind].second = (res[ind].first + res[ind].second) / 2; if (nope) { res[ind].second++; if (res[ind].second - res[ind].first < 2 && res[ind].first > 0) res[ind].first--; if (res[ind].second - res[ind].first < 2 && res[ind].second < r) res[ind].second++; } } } for (int i=0; i<d; i++) { pos[i] = res[i].first; } znalazlem(pos.data()); 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 | #include "cielib.h" #include <algorithm> #include <utility> #include <vector> using namespace std; using pii = pair<int, int>; int main() { int d = podajD(); int r = podajR(); vector<int> pos(d); vector<pii> res(d, {0, r}); while (1) { auto it = max_element( res.begin(), res.end(), [](pii const& a, pii const& b) { return a.second - a.first < b.second - b.first; }); int delta = it->second - it->first; if (!delta) { break; } int max_d = (delta+1) / 2; for (int i=0; i<d; i++) { pos[i] = (res[i].first + res[i].second) / 2; } int ind = it - res.begin(); pos[ind] = res[ind].first; czyCieplo(pos.data()); pos[ind] = res[ind].second; bool cright = czyCieplo(pos.data()); pos[ind] = res[ind].first; bool cleft = czyCieplo(pos.data()); if (cright) { if (delta == 2) { res[ind].first = res[ind].second; } else { res[ind].first = res[ind].second - max_d; } } else if (cleft) { if (delta == 2) { res[ind].second = res[ind].first; } else { res[ind].second = res[ind].first + max_d; } } else { bool nope = res[ind].first % 2 != res[ind].second % 2; res[ind].first = res[ind].second = (res[ind].first + res[ind].second) / 2; if (nope) { res[ind].second++; if (res[ind].second - res[ind].first < 2 && res[ind].first > 0) res[ind].first--; if (res[ind].second - res[ind].first < 2 && res[ind].second < r) res[ind].second++; } } } for (int i=0; i<d; i++) { pos[i] = res[i].first; } znalazlem(pos.data()); return 0; } |