#include <iostream> #include <cstdlib> #include <cmath> #include <stack> #include "cielib.h" using namespace std; int d; int r; int t[500]; int min_loc[500]; int max_loc[500]; int getMaxDim() { int res = 0; for(int i=1; i<d; i++) { if((max_loc[res]-min_loc[res])<(max_loc[i]-min_loc[i])) { res = i; } } return res; } int main() { d = podajD(); r = podajR(); for(int i=0; i<d; i++){ min_loc[i]=0; max_loc[i]=r; } while(true) { int max_dim = getMaxDim(); if((max_loc[max_dim]-min_loc[max_dim]) == 0) { break; } for(int i=0; i<d; i++){ t[i] = (min_loc[i] + max_loc[i])/2; } if(max_loc[max_dim] - min_loc[max_dim] > 1){ t[max_dim] = min_loc[max_dim]; czyCieplo(t); t[max_dim] = max_loc[max_dim]; if(czyCieplo(t)) { min_loc[max_dim] = (min_loc[max_dim] + max_loc[max_dim])/2 +1; } else { max_loc[max_dim] = min_loc[max_dim]+(max_loc[max_dim]-min_loc[max_dim]+1)/2; } } else { if(min_loc[max_dim]>0) { t[max_dim] = min_loc[max_dim]-1; czyCieplo(t); t[max_dim] = max_loc[max_dim]; if(czyCieplo(t)) { min_loc[max_dim] = max_loc[max_dim]; } else { max_loc[max_dim] = min_loc[max_dim]; } } else { t[max_dim] = max_loc[max_dim]+1; czyCieplo(t); t[max_dim] = min_loc[max_dim]; if(czyCieplo(t)) { max_loc[max_dim] = min_loc[max_dim]; } else { min_loc[max_dim] = max_loc[max_dim]; } } } } znalazlem(min_loc); }
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 | #include <iostream> #include <cstdlib> #include <cmath> #include <stack> #include "cielib.h" using namespace std; int d; int r; int t[500]; int min_loc[500]; int max_loc[500]; int getMaxDim() { int res = 0; for(int i=1; i<d; i++) { if((max_loc[res]-min_loc[res])<(max_loc[i]-min_loc[i])) { res = i; } } return res; } int main() { d = podajD(); r = podajR(); for(int i=0; i<d; i++){ min_loc[i]=0; max_loc[i]=r; } while(true) { int max_dim = getMaxDim(); if((max_loc[max_dim]-min_loc[max_dim]) == 0) { break; } for(int i=0; i<d; i++){ t[i] = (min_loc[i] + max_loc[i])/2; } if(max_loc[max_dim] - min_loc[max_dim] > 1){ t[max_dim] = min_loc[max_dim]; czyCieplo(t); t[max_dim] = max_loc[max_dim]; if(czyCieplo(t)) { min_loc[max_dim] = (min_loc[max_dim] + max_loc[max_dim])/2 +1; } else { max_loc[max_dim] = min_loc[max_dim]+(max_loc[max_dim]-min_loc[max_dim]+1)/2; } } else { if(min_loc[max_dim]>0) { t[max_dim] = min_loc[max_dim]-1; czyCieplo(t); t[max_dim] = max_loc[max_dim]; if(czyCieplo(t)) { min_loc[max_dim] = max_loc[max_dim]; } else { max_loc[max_dim] = min_loc[max_dim]; } } else { t[max_dim] = max_loc[max_dim]+1; czyCieplo(t); t[max_dim] = min_loc[max_dim]; if(czyCieplo(t)) { max_loc[max_dim] = min_loc[max_dim]; } else { min_loc[max_dim] = max_loc[max_dim]; } } } } znalazlem(min_loc); } |