Niestety, nie byliśmy w stanie w pełni poprawnie wyświetlić tego pliku, ponieważ nie jest zakodowany w UTF-8.
Możesz pobrać ten plik i spróbować otworzyć go samodzielnie.
#include "cielib.h" #include <vector> #include <set> #include <cstdlib> #ifdef _DEBUG #include <cstdio> #include <iostream> #endif // #define _DEBUG_EXTRA using namespace std; const int MAX_DIMENSIONS = 500; typedef int coords_array[MAX_DIMENSIONS]; coords_array min_possible_coord; coords_array max_possible_coord; coords_array middle_coord; int questions_still_can_use; int DIMENSIONS; int czyCieplo__(int a[]) { questions_still_can_use--; int res_to_return = czyCieplo(a); #ifdef _DEBUG_EXTRA cerr << "(czyCieplo__) coords:"; for(int d=0; d < DIMENSIONS; d++) cerr << " " << a[d]; cerr << " returned " << res_to_return << endl; #endif return res_to_return; } /* void refstep(int &dim_checked) { do { dim_checked++; dim_checked %= DIMENSIONS; } while(max_possible_coord[dim_checked] == min_possible_coord[dim_checked]); // TODO: re-check is this correct } */ /* does it really work at all?.. int (©_but_change_at_pos(int orig_coords[MAX_DIMENSIONS], int idx, int val))[MAX_DIMENSIONS] { int res[MAX_DIMENSIONS]; memcpy(res, orig_coords, DIMENSIONS*sizeof(int)); res[idx] = val; return res; } */ int main(int argc, char* argv[]) { #ifdef _DEBUG freopen("input.txt", "rt", stdin); #endif // srand(17); DIMENSIONS = podajD(); int MAX_COORD = podajR(); questions_still_can_use = podajK(); for(int d=0; d < DIMENSIONS; d++) { min_possible_coord[d] = 0; max_possible_coord[d] = MAX_COORD; middle_coord[d] = MAX_COORD/2; } int max_possible_delta = MAX_COORD - MAX_COORD/2; int dimensions_still_not_found = DIMENSIONS; for(int dim_checked = 0; questions_still_can_use >= 3 && dimensions_still_not_found > 0; /*refstep(dim_checked)*/ dim_checked = (dim_checked+1)%DIMENSIONS) { min_possible_coord[dim_checked] = max(min_possible_coord[dim_checked], middle_coord[dim_checked] - max_possible_delta); max_possible_coord[dim_checked] = min(max_possible_coord[dim_checked], middle_coord[dim_checked] + max_possible_delta); while(min_possible_coord[dim_checked] < max_possible_coord[dim_checked]) { // can be breaked in some other cases too, see "break"-s int sz_div_3 = (max_possible_coord[dim_checked] - min_possible_coord[dim_checked]) / 3; if(questions_still_can_use < 3) goto break_all; int m1 = min_possible_coord[dim_checked] + sz_div_3; int m2 = max_possible_coord[dim_checked] - sz_div_3; if(sz_div_3==0 && max_possible_coord[dim_checked] - min_possible_coord[dim_checked] > 1) { if(rand() & 1) m2--; else m1++; } /* else if(sz_div_3 > 50) { int t = (rand() % (sz_div_3))/2 + 1; if(t > 1) { // m1 += rand() % t; m1 -= rand() % t; // m2 -= rand() % t; m2 += rand() % t; } } */ middle_coord[dim_checked] = m1; czyCieplo__(middle_coord); // the ONLY goal is to set point to compare with middle_coord[dim_checked] = m2; if(czyCieplo__(middle_coord)==1) { // f(m2) < f(m1) min_possible_coord[dim_checked] = min(m1+1, max_possible_coord[dim_checked]); } else { middle_coord[dim_checked] = m1; if(czyCieplo__(middle_coord)==1) { // f(m1) < f(m2) max_possible_coord[dim_checked] = max(m2-1, min_possible_coord[dim_checked]); } else { // f(m1) == f(m2), so we don't know where mininmum actually is if(min_possible_coord[dim_checked] < max_possible_coord[dim_checked]) { #ifdef _DEBUG int curr_coordinate_backup_old = middle_coord[dim_checked]; #endif if(max_possible_coord[dim_checked] - min_possible_coord[dim_checked] > 3) { middle_coord[dim_checked] = (max_possible_coord[dim_checked] + min_possible_coord[dim_checked]) / 2; } else { middle_coord[dim_checked] = min_possible_coord[dim_checked] + rand() % (max_possible_coord[dim_checked] - min_possible_coord[dim_checked] + 1); } #ifdef _DEBUG cerr << "\t\t\t\t\t\t\t" << max_possible_delta << endl; for(int d=0; d < DIMENSIONS; d++) cerr << min_possible_coord[d] << " " << middle_coord[d] << " " << max_possible_coord[d] << endl; #ifdef _DEBUG_EXTRA int curr_coordinate_backup_new = middle_coord[dim_checked]; if(czyCieplo__(middle_coord)) { _DEBUG_ERROR("��������� ��� �� ������� ���� ��� �� ������ ����"); } middle_coord[dim_checked] = curr_coordinate_backup_old; if(czyCieplo__(middle_coord)) { _DEBUG_ERROR("��������� ��� �� ������� ���� ��� �� ������ ����"); } middle_coord[dim_checked] = curr_coordinate_backup_new; #endif #endif if(max_possible_coord[dim_checked] - min_possible_coord[dim_checked] < max_possible_delta) max_possible_delta = max_possible_coord[dim_checked] - min_possible_coord[dim_checked]; break; // breaks ternary search only } } } if(min_possible_coord[dim_checked]==max_possible_coord[dim_checked]) { /* middle_coord[dim_checked] = min_possible_coord[dim_checked]; max_possible_delta = 0; dimensions_still_not_found--; */ #ifdef _DEBUG cerr << "coords:"; for(int d=0; d < DIMENSIONS; d++) cerr << " " << middle_coord[d]; cerr << endl; #endif goto break_all; // ������, �� �� ���� ���� } } } break_all: znalazlem(middle_coord); 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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | #include "cielib.h" #include <vector> #include <set> #include <cstdlib> #ifdef _DEBUG #include <cstdio> #include <iostream> #endif // #define _DEBUG_EXTRA using namespace std; const int MAX_DIMENSIONS = 500; typedef int coords_array[MAX_DIMENSIONS]; coords_array min_possible_coord; coords_array max_possible_coord; coords_array middle_coord; int questions_still_can_use; int DIMENSIONS; int czyCieplo__(int a[]) { questions_still_can_use--; int res_to_return = czyCieplo(a); #ifdef _DEBUG_EXTRA cerr << "(czyCieplo__) coords:"; for(int d=0; d < DIMENSIONS; d++) cerr << " " << a[d]; cerr << " returned " << res_to_return << endl; #endif return res_to_return; } /* void refstep(int &dim_checked) { do { dim_checked++; dim_checked %= DIMENSIONS; } while(max_possible_coord[dim_checked] == min_possible_coord[dim_checked]); // TODO: re-check is this correct } */ /* does it really work at all?.. int (©_but_change_at_pos(int orig_coords[MAX_DIMENSIONS], int idx, int val))[MAX_DIMENSIONS] { int res[MAX_DIMENSIONS]; memcpy(res, orig_coords, DIMENSIONS*sizeof(int)); res[idx] = val; return res; } */ int main(int argc, char* argv[]) { #ifdef _DEBUG freopen("input.txt", "rt", stdin); #endif // srand(17); DIMENSIONS = podajD(); int MAX_COORD = podajR(); questions_still_can_use = podajK(); for(int d=0; d < DIMENSIONS; d++) { min_possible_coord[d] = 0; max_possible_coord[d] = MAX_COORD; middle_coord[d] = MAX_COORD/2; } int max_possible_delta = MAX_COORD - MAX_COORD/2; int dimensions_still_not_found = DIMENSIONS; for(int dim_checked = 0; questions_still_can_use >= 3 && dimensions_still_not_found > 0; /*refstep(dim_checked)*/ dim_checked = (dim_checked+1)%DIMENSIONS) { min_possible_coord[dim_checked] = max(min_possible_coord[dim_checked], middle_coord[dim_checked] - max_possible_delta); max_possible_coord[dim_checked] = min(max_possible_coord[dim_checked], middle_coord[dim_checked] + max_possible_delta); while(min_possible_coord[dim_checked] < max_possible_coord[dim_checked]) { // can be breaked in some other cases too, see "break"-s int sz_div_3 = (max_possible_coord[dim_checked] - min_possible_coord[dim_checked]) / 3; if(questions_still_can_use < 3) goto break_all; int m1 = min_possible_coord[dim_checked] + sz_div_3; int m2 = max_possible_coord[dim_checked] - sz_div_3; if(sz_div_3==0 && max_possible_coord[dim_checked] - min_possible_coord[dim_checked] > 1) { if(rand() & 1) m2--; else m1++; } /* else if(sz_div_3 > 50) { int t = (rand() % (sz_div_3))/2 + 1; if(t > 1) { // m1 += rand() % t; m1 -= rand() % t; // m2 -= rand() % t; m2 += rand() % t; } } */ middle_coord[dim_checked] = m1; czyCieplo__(middle_coord); // the ONLY goal is to set point to compare with middle_coord[dim_checked] = m2; if(czyCieplo__(middle_coord)==1) { // f(m2) < f(m1) min_possible_coord[dim_checked] = min(m1+1, max_possible_coord[dim_checked]); } else { middle_coord[dim_checked] = m1; if(czyCieplo__(middle_coord)==1) { // f(m1) < f(m2) max_possible_coord[dim_checked] = max(m2-1, min_possible_coord[dim_checked]); } else { // f(m1) == f(m2), so we don't know where mininmum actually is if(min_possible_coord[dim_checked] < max_possible_coord[dim_checked]) { #ifdef _DEBUG int curr_coordinate_backup_old = middle_coord[dim_checked]; #endif if(max_possible_coord[dim_checked] - min_possible_coord[dim_checked] > 3) { middle_coord[dim_checked] = (max_possible_coord[dim_checked] + min_possible_coord[dim_checked]) / 2; } else { middle_coord[dim_checked] = min_possible_coord[dim_checked] + rand() % (max_possible_coord[dim_checked] - min_possible_coord[dim_checked] + 1); } #ifdef _DEBUG cerr << "\t\t\t\t\t\t\t" << max_possible_delta << endl; for(int d=0; d < DIMENSIONS; d++) cerr << min_possible_coord[d] << " " << middle_coord[d] << " " << max_possible_coord[d] << endl; #ifdef _DEBUG_EXTRA int curr_coordinate_backup_new = middle_coord[dim_checked]; if(czyCieplo__(middle_coord)) { _DEBUG_ERROR("��������� ��� �� ������� ���� ��� �� ������ ����"); } middle_coord[dim_checked] = curr_coordinate_backup_old; if(czyCieplo__(middle_coord)) { _DEBUG_ERROR("��������� ��� �� ������� ���� ��� �� ������ ����"); } middle_coord[dim_checked] = curr_coordinate_backup_new; #endif #endif if(max_possible_coord[dim_checked] - min_possible_coord[dim_checked] < max_possible_delta) max_possible_delta = max_possible_coord[dim_checked] - min_possible_coord[dim_checked]; break; // breaks ternary search only } } } if(min_possible_coord[dim_checked]==max_possible_coord[dim_checked]) { /* middle_coord[dim_checked] = min_possible_coord[dim_checked]; max_possible_delta = 0; dimensions_still_not_found--; */ #ifdef _DEBUG cerr << "coords:"; for(int d=0; d < DIMENSIONS; d++) cerr << " " << middle_coord[d]; cerr << endl; #endif goto break_all; // ������, �� �� ���� ���� } } } break_all: znalazlem(middle_coord); return 0; } |