#include "cielib.h" #include <queue> #include <cstdlib> using namespace std; struct str{ int l; int r; // [l, r) int ix; }; bool operator< (str const& x, str const& y) { return (x.r-x.l) < (y.r-y.l); } int d; int t[1000]; int res[1000]; int R; int main() { srand(0); d = podajD(); R = podajR(); for(int i = 0; i < d; ++i) { t[i] = (R+1)/2; } priority_queue<str> q; for(int i=0; i<d; i++) q.push({0, R+1, i}); while(!q.empty()) { str x = q.top(); q.pop(); if(x.r - x.l == 1) { res[x.ix] = x.l; continue; } if(x.r - x.l == 2) { if(x.l == 0) x.r+=1; else x.l-=1; } bool lr = 0, rl = 0; int k = (x.r + x.l)/2; t[x.ix] = x.l; czyCieplo(t); t[x.ix] = x.r-1; lr = czyCieplo(t); t[x.ix] = x.l; if(!lr) rl = czyCieplo(t); if((x.r - x.l )%2 == 0) { if(!lr && !rl) { t[x.ix] = k; q.push({k-1, k+1, x.ix}); continue; } if(lr) { t[x.ix] = (k + x.r)/2; q.push({k, x.r, x.ix}); continue; } // if rl t[x.ix] = (x.l + k)/2; q.push({x.l, k, x.ix}); continue; } else // %2 == 1 { if(!lr && !rl) { t[x.ix] = k; q.push({k, k+1, x.ix}); continue; } if(lr) { t[x.ix] = (k+1 + x.r)/2; q.push({k+1, x.r, x.ix}); continue; } if(rl) { t[x.ix] = (x.l + k)/2; q.push({x.l, k, x.ix}); continue; } } } znalazlem(res); }
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 | #include "cielib.h" #include <queue> #include <cstdlib> using namespace std; struct str{ int l; int r; // [l, r) int ix; }; bool operator< (str const& x, str const& y) { return (x.r-x.l) < (y.r-y.l); } int d; int t[1000]; int res[1000]; int R; int main() { srand(0); d = podajD(); R = podajR(); for(int i = 0; i < d; ++i) { t[i] = (R+1)/2; } priority_queue<str> q; for(int i=0; i<d; i++) q.push({0, R+1, i}); while(!q.empty()) { str x = q.top(); q.pop(); if(x.r - x.l == 1) { res[x.ix] = x.l; continue; } if(x.r - x.l == 2) { if(x.l == 0) x.r+=1; else x.l-=1; } bool lr = 0, rl = 0; int k = (x.r + x.l)/2; t[x.ix] = x.l; czyCieplo(t); t[x.ix] = x.r-1; lr = czyCieplo(t); t[x.ix] = x.l; if(!lr) rl = czyCieplo(t); if((x.r - x.l )%2 == 0) { if(!lr && !rl) { t[x.ix] = k; q.push({k-1, k+1, x.ix}); continue; } if(lr) { t[x.ix] = (k + x.r)/2; q.push({k, x.r, x.ix}); continue; } // if rl t[x.ix] = (x.l + k)/2; q.push({x.l, k, x.ix}); continue; } else // %2 == 1 { if(!lr && !rl) { t[x.ix] = k; q.push({k, k+1, x.ix}); continue; } if(lr) { t[x.ix] = (k+1 + x.r)/2; q.push({k+1, x.r, x.ix}); continue; } if(rl) { t[x.ix] = (x.l + k)/2; q.push({x.l, k, x.ix}); continue; } } } znalazlem(res); } |