#include <iostream> #include <vector> #include "cielib.h" using namespace std; int r,d; int high[501]; int low[501]; int mid[501]; int main() { d = podajD(); r = podajR(); for(int i=0;i<d;i++) high[i] = r; for(;;){ for(int i=0;i<d;i++){ mid[i] = (low[i] + high[i])/2; if(mid[i] == 0 && high[i] != 0) mid[i] = 1; if(mid[i] == r && low[i] != r) mid[i] = r-1; } /* for(int i=0;i<d;i++) cout<<mid[i]<<" "; cout<<endl;*/ czyCieplo(mid); vector<int> repl(d); for(int i=0;i<d;i++){ bool b1= false, b2 = false; if(mid[i] < r){ mid[i]++; b1 = czyCieplo(mid); mid[i]--; b2 = czyCieplo(mid); if(b2 == true) repl[i] += 2; } b1= false; b2 = false; if(mid[i] > 0){ mid[i]--; b1 = czyCieplo(mid); mid[i]++; b2 = czyCieplo(mid); if(b2 == true) repl[i] += 1; } } int ct = 0; for(int i=0;i<d;i++){ if(repl[i] == 3 || (mid[i] == r && repl[i] == 1) || (mid[i] == 0 && repl[i] == 2)) {/*cout<<"OBA"<<i<<endl;*/ct++;} if(repl[i] >= 2){ high[i] = mid[i]-1;/*cout<<"Wymiar: "<<i<<" dol \n";*/} if(repl[i] == 1 || repl[i] == 3) {low[i] = mid[i]+1; /*cout<<"Wymiar: "<<i<<" gora \n";*/} } if(ct == d) znalazlem(mid); } 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 | #include <iostream> #include <vector> #include "cielib.h" using namespace std; int r,d; int high[501]; int low[501]; int mid[501]; int main() { d = podajD(); r = podajR(); for(int i=0;i<d;i++) high[i] = r; for(;;){ for(int i=0;i<d;i++){ mid[i] = (low[i] + high[i])/2; if(mid[i] == 0 && high[i] != 0) mid[i] = 1; if(mid[i] == r && low[i] != r) mid[i] = r-1; } /* for(int i=0;i<d;i++) cout<<mid[i]<<" "; cout<<endl;*/ czyCieplo(mid); vector<int> repl(d); for(int i=0;i<d;i++){ bool b1= false, b2 = false; if(mid[i] < r){ mid[i]++; b1 = czyCieplo(mid); mid[i]--; b2 = czyCieplo(mid); if(b2 == true) repl[i] += 2; } b1= false; b2 = false; if(mid[i] > 0){ mid[i]--; b1 = czyCieplo(mid); mid[i]++; b2 = czyCieplo(mid); if(b2 == true) repl[i] += 1; } } int ct = 0; for(int i=0;i<d;i++){ if(repl[i] == 3 || (mid[i] == r && repl[i] == 1) || (mid[i] == 0 && repl[i] == 2)) {/*cout<<"OBA"<<i<<endl;*/ct++;} if(repl[i] >= 2){ high[i] = mid[i]-1;/*cout<<"Wymiar: "<<i<<" dol \n";*/} if(repl[i] == 1 || repl[i] == 3) {low[i] = mid[i]+1; /*cout<<"Wymiar: "<<i<<" gora \n";*/} } if(ct == d) znalazlem(mid); } return 0; } |