#include <cstdio> #include <vector> #include <algorithm> #include "cielib.h" typedef int smallnum; int main() { smallnum d = podajD(); smallnum r = podajR(); std::vector<smallnum> lower_bounds(d, 0); std::vector<smallnum> upper_bounds(d, r); std::vector<smallnum> distances(d, r); std::vector<smallnum> responses1(d, 0); std::vector<smallnum> responses2(d, 0); bool converged = false; // Main loop while (!converged) { // printf("=============== DEBUG - START ROUND ================\n"); // Step 1. Let's make first jumps for (smallnum jump_dimension = 0; jump_dimension < d; jump_dimension++) { std::vector<smallnum> current_pos(d); std::vector<smallnum> jump_pos(d); smallnum jump_distance = upper_bounds[jump_dimension] - lower_bounds[jump_dimension]; if (jump_distance == 0) {continue;} for (smallnum i = 0; i < d; i++) { if (i == jump_dimension) { current_pos[i] = lower_bounds[i]; jump_pos[i] = upper_bounds[i]; } else { current_pos[i] = (lower_bounds[i] + upper_bounds[i]) / 2; jump_pos[i] = (lower_bounds[i] + upper_bounds[i]) / 2; } } czyCieplo(current_pos.data()); responses1[jump_dimension] = czyCieplo(jump_pos.data()); // printf("DEBUG - jump dimension %d response %d\n", jump_dimension, responses1[jump_dimension]); if (jump_distance % 2 == 0) { responses2[jump_dimension] = czyCieplo(current_pos.data()); // printf("DEBUG - jump dimension %d response 2 %d\n", jump_dimension, responses2[jump_dimension]); } } // Step 2. Let's narrow down our selection for (smallnum jump_dimension = 0; jump_dimension < d; jump_dimension++) { smallnum jump_distance = upper_bounds[jump_dimension] - lower_bounds[jump_dimension]; if (jump_distance == 0) {continue;} if (jump_distance == 2) { if (responses1[jump_dimension]) { lower_bounds[jump_dimension] = upper_bounds[jump_dimension]; } else if (responses2[jump_dimension]) { upper_bounds[jump_dimension] = lower_bounds[jump_dimension]; } else { smallnum sum = lower_bounds[jump_dimension] + upper_bounds[jump_dimension]; upper_bounds[jump_dimension] = sum / 2; lower_bounds[jump_dimension] = sum / 2; } continue; } if (responses1[jump_dimension]) { smallnum sum = lower_bounds[jump_dimension] + upper_bounds[jump_dimension]; lower_bounds[jump_dimension] = sum / 2; lower_bounds[jump_dimension] = std::min(lower_bounds[jump_dimension], upper_bounds[jump_dimension] - 2); } else { if (jump_distance % 2 == 0) { if (responses2[jump_dimension]) { smallnum sum = lower_bounds[jump_dimension] + upper_bounds[jump_dimension]; if (sum % 2 == 1) { upper_bounds[jump_dimension] = (sum + 1) / 2; upper_bounds[jump_dimension] = std::max(upper_bounds[jump_dimension], lower_bounds[jump_dimension] + 2); } else { upper_bounds[jump_dimension] = sum / 2; } } else { // We are exactly in the middle smallnum sum = lower_bounds[jump_dimension] + upper_bounds[jump_dimension]; upper_bounds[jump_dimension] = sum / 2; lower_bounds[jump_dimension] = sum / 2; } } else { smallnum sum = lower_bounds[jump_dimension] + upper_bounds[jump_dimension]; if (sum % 2 == 1) { upper_bounds[jump_dimension] = (sum + 1) / 2; upper_bounds[jump_dimension] = std::max(upper_bounds[jump_dimension], lower_bounds[jump_dimension] + 2); } else { upper_bounds[jump_dimension] = sum / 2; upper_bounds[jump_dimension] = std::max(upper_bounds[jump_dimension], lower_bounds[jump_dimension] + 2); } } } } // printf("DEBUG - bounds after jumps\n"); // for (unsigned long i = 0; i < lower_bounds.size(); i++) { // printf("%d, ", lower_bounds[i]); // } // printf("\n"); // for (unsigned long i = 0; i < upper_bounds.size(); i++) { // printf("%d, ", upper_bounds[i]); // } // printf("\n"); // Step 3. check for convergence converged = true; for (smallnum check_dimension = 0; check_dimension < d; check_dimension++) { if (upper_bounds[check_dimension] != lower_bounds[check_dimension]) { converged = false; } } } znalazlem(upper_bounds.data()); 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 | #include <cstdio> #include <vector> #include <algorithm> #include "cielib.h" typedef int smallnum; int main() { smallnum d = podajD(); smallnum r = podajR(); std::vector<smallnum> lower_bounds(d, 0); std::vector<smallnum> upper_bounds(d, r); std::vector<smallnum> distances(d, r); std::vector<smallnum> responses1(d, 0); std::vector<smallnum> responses2(d, 0); bool converged = false; // Main loop while (!converged) { // printf("=============== DEBUG - START ROUND ================\n"); // Step 1. Let's make first jumps for (smallnum jump_dimension = 0; jump_dimension < d; jump_dimension++) { std::vector<smallnum> current_pos(d); std::vector<smallnum> jump_pos(d); smallnum jump_distance = upper_bounds[jump_dimension] - lower_bounds[jump_dimension]; if (jump_distance == 0) {continue;} for (smallnum i = 0; i < d; i++) { if (i == jump_dimension) { current_pos[i] = lower_bounds[i]; jump_pos[i] = upper_bounds[i]; } else { current_pos[i] = (lower_bounds[i] + upper_bounds[i]) / 2; jump_pos[i] = (lower_bounds[i] + upper_bounds[i]) / 2; } } czyCieplo(current_pos.data()); responses1[jump_dimension] = czyCieplo(jump_pos.data()); // printf("DEBUG - jump dimension %d response %d\n", jump_dimension, responses1[jump_dimension]); if (jump_distance % 2 == 0) { responses2[jump_dimension] = czyCieplo(current_pos.data()); // printf("DEBUG - jump dimension %d response 2 %d\n", jump_dimension, responses2[jump_dimension]); } } // Step 2. Let's narrow down our selection for (smallnum jump_dimension = 0; jump_dimension < d; jump_dimension++) { smallnum jump_distance = upper_bounds[jump_dimension] - lower_bounds[jump_dimension]; if (jump_distance == 0) {continue;} if (jump_distance == 2) { if (responses1[jump_dimension]) { lower_bounds[jump_dimension] = upper_bounds[jump_dimension]; } else if (responses2[jump_dimension]) { upper_bounds[jump_dimension] = lower_bounds[jump_dimension]; } else { smallnum sum = lower_bounds[jump_dimension] + upper_bounds[jump_dimension]; upper_bounds[jump_dimension] = sum / 2; lower_bounds[jump_dimension] = sum / 2; } continue; } if (responses1[jump_dimension]) { smallnum sum = lower_bounds[jump_dimension] + upper_bounds[jump_dimension]; lower_bounds[jump_dimension] = sum / 2; lower_bounds[jump_dimension] = std::min(lower_bounds[jump_dimension], upper_bounds[jump_dimension] - 2); } else { if (jump_distance % 2 == 0) { if (responses2[jump_dimension]) { smallnum sum = lower_bounds[jump_dimension] + upper_bounds[jump_dimension]; if (sum % 2 == 1) { upper_bounds[jump_dimension] = (sum + 1) / 2; upper_bounds[jump_dimension] = std::max(upper_bounds[jump_dimension], lower_bounds[jump_dimension] + 2); } else { upper_bounds[jump_dimension] = sum / 2; } } else { // We are exactly in the middle smallnum sum = lower_bounds[jump_dimension] + upper_bounds[jump_dimension]; upper_bounds[jump_dimension] = sum / 2; lower_bounds[jump_dimension] = sum / 2; } } else { smallnum sum = lower_bounds[jump_dimension] + upper_bounds[jump_dimension]; if (sum % 2 == 1) { upper_bounds[jump_dimension] = (sum + 1) / 2; upper_bounds[jump_dimension] = std::max(upper_bounds[jump_dimension], lower_bounds[jump_dimension] + 2); } else { upper_bounds[jump_dimension] = sum / 2; upper_bounds[jump_dimension] = std::max(upper_bounds[jump_dimension], lower_bounds[jump_dimension] + 2); } } } } // printf("DEBUG - bounds after jumps\n"); // for (unsigned long i = 0; i < lower_bounds.size(); i++) { // printf("%d, ", lower_bounds[i]); // } // printf("\n"); // for (unsigned long i = 0; i < upper_bounds.size(); i++) { // printf("%d, ", upper_bounds[i]); // } // printf("\n"); // Step 3. check for convergence converged = true; for (smallnum check_dimension = 0; check_dimension < d; check_dimension++) { if (upper_bounds[check_dimension] != lower_bounds[check_dimension]) { converged = false; } } } znalazlem(upper_bounds.data()); return 0; } |