#include "cielib.h" #include <random> void Solve() { int d = podajD(), r = podajR(), k = podajK(), ilek = 0; int *min = new int[d]; int *max = new int[d]; int *a = new int[d]; int *b = new int[d]; bool found = false; for (int i=0;i<d;i++) { min[i] = 0; max[i] = r; } while (!found) { int wymiaryDoRedukcji = 0; bool reduced = false; for (int i=0;i<d && !reduced;i++) { for (int i = 0;i<d;i++) a[i] = min[i] + (max[i] - min[i]) / 2; if (min[i]==max[i]) //pomijam juz zredukowane wymiary continue; else wymiaryDoRedukcji++; a[i] = min[i]; czyCieplo(a); //pierwsza sciana ilek++; a[i] = max[i]; if (czyCieplo(a)) //druga sciana { if (min[i]+1 == max[i]) min[i]++; else min[i] = min[i] + (max[i]-min[i])/2; reduced = true; } else { a[i] = min[i]; if (czyCieplo(a)) //pierwsza sciana { max[i] = min[i] + (max[i]-min[i])/2; reduced = true; } ilek++; } ilek++; } if (wymiaryDoRedukcji==0) { found = true; znalazlem(min); } else { if (!reduced)//znajduje sie w srodku ? { for (int i=0;i<d;i++) { a[i] = min[i] + (max[i]-min[i])/2; b[i] = a[i]; } while(ilek+1<k) { if (czyCieplo(a)) { for (int i=0;i<d;i++) b[i] = a[i]; } for (int i=0;i<d;i++) a[i] = min[i] + (std::rand() % (max[i] - min[i] + 1)); ilek++; } found = true; znalazlem(b); } } } delete min; delete max; delete a; delete b; } int main() { Solve(); 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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | #include "cielib.h" #include <random> void Solve() { int d = podajD(), r = podajR(), k = podajK(), ilek = 0; int *min = new int[d]; int *max = new int[d]; int *a = new int[d]; int *b = new int[d]; bool found = false; for (int i=0;i<d;i++) { min[i] = 0; max[i] = r; } while (!found) { int wymiaryDoRedukcji = 0; bool reduced = false; for (int i=0;i<d && !reduced;i++) { for (int i = 0;i<d;i++) a[i] = min[i] + (max[i] - min[i]) / 2; if (min[i]==max[i]) //pomijam juz zredukowane wymiary continue; else wymiaryDoRedukcji++; a[i] = min[i]; czyCieplo(a); //pierwsza sciana ilek++; a[i] = max[i]; if (czyCieplo(a)) //druga sciana { if (min[i]+1 == max[i]) min[i]++; else min[i] = min[i] + (max[i]-min[i])/2; reduced = true; } else { a[i] = min[i]; if (czyCieplo(a)) //pierwsza sciana { max[i] = min[i] + (max[i]-min[i])/2; reduced = true; } ilek++; } ilek++; } if (wymiaryDoRedukcji==0) { found = true; znalazlem(min); } else { if (!reduced)//znajduje sie w srodku ? { for (int i=0;i<d;i++) { a[i] = min[i] + (max[i]-min[i])/2; b[i] = a[i]; } while(ilek+1<k) { if (czyCieplo(a)) { for (int i=0;i<d;i++) b[i] = a[i]; } for (int i=0;i<d;i++) a[i] = min[i] + (std::rand() % (max[i] - min[i] + 1)); ilek++; } found = true; znalazlem(b); } } } delete min; delete max; delete a; delete b; } int main() { Solve(); return 0; } |