#include <stdio.h> #include <utility> #include <vector> #include "cielib.h" int main() { long d = podajD(); long k = podajK(); long r = podajR(); std::vector<bool> ready(d, false); long ready_amount = 0; std::vector<int> coordinates(d, r/2); std::vector<std::pair<int, int>> b_search( d, std::pair<int, int>(0, r) ); czyCieplo(&coordinates[0]); while(ready_amount != d) { for(int i=0; i<d; i++) { if (!ready[i]) { int middle = coordinates[i]; std::vector<int> left(coordinates); std::vector<int> right(coordinates); left[i] = b_search[i].first; right[i] = b_search[i].second; bool is_odd = (b_search[i].second - b_search[i].first)%2; if (right[i] - left[i] <= 2) { ready[i] = true; ready_amount++; if (czyCieplo(&left[0])) { coordinates[i] = left[i]; } else if (czyCieplo(&right[0])) { coordinates[i] = right[i]; } else if (czyCieplo(&left[0])) { coordinates[i] = left[i]; } } else { if (czyCieplo(&left[0])) { b_search[i].second = middle; } else if (czyCieplo(&right[0])) { b_search[i].first = middle; if (is_odd) { b_search[i].first++; } } else if(czyCieplo(&left[0])) { b_search[i].second = middle; } else { if (is_odd) { b_search[i].first = middle; } else { ready[i] = true; ready_amount++; } } } if (b_search[i].second - b_search[i].first == 1) { if (b_search[i].first) b_search[i].first--; else b_search[i].second++; } } } for(int i=0; i<d; i++) { if (!ready[i]) { coordinates[i] = (b_search[i].first + b_search[i].second)/2; } } czyCieplo(&coordinates[0]); } znalazlem(&coordinates[0]); 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 | #include <stdio.h> #include <utility> #include <vector> #include "cielib.h" int main() { long d = podajD(); long k = podajK(); long r = podajR(); std::vector<bool> ready(d, false); long ready_amount = 0; std::vector<int> coordinates(d, r/2); std::vector<std::pair<int, int>> b_search( d, std::pair<int, int>(0, r) ); czyCieplo(&coordinates[0]); while(ready_amount != d) { for(int i=0; i<d; i++) { if (!ready[i]) { int middle = coordinates[i]; std::vector<int> left(coordinates); std::vector<int> right(coordinates); left[i] = b_search[i].first; right[i] = b_search[i].second; bool is_odd = (b_search[i].second - b_search[i].first)%2; if (right[i] - left[i] <= 2) { ready[i] = true; ready_amount++; if (czyCieplo(&left[0])) { coordinates[i] = left[i]; } else if (czyCieplo(&right[0])) { coordinates[i] = right[i]; } else if (czyCieplo(&left[0])) { coordinates[i] = left[i]; } } else { if (czyCieplo(&left[0])) { b_search[i].second = middle; } else if (czyCieplo(&right[0])) { b_search[i].first = middle; if (is_odd) { b_search[i].first++; } } else if(czyCieplo(&left[0])) { b_search[i].second = middle; } else { if (is_odd) { b_search[i].first = middle; } else { ready[i] = true; ready_amount++; } } } if (b_search[i].second - b_search[i].first == 1) { if (b_search[i].first) b_search[i].first--; else b_search[i].second++; } } } for(int i=0; i<d; i++) { if (!ready[i]) { coordinates[i] = (b_search[i].first + b_search[i].second)/2; } } czyCieplo(&coordinates[0]); } znalazlem(&coordinates[0]); return 0; }; |