#include "cielib.h" int main() { int d = podajD(); int k = podajK(); int r = podajR(); int ileSkonczonych = 0, odpytan = 0; int min[d], max[d], answer[d]; for (int i=0; i<d; i++) { min[i] = 0; max[i] = r; answer[i] = r/2; } while (ileSkonczonych != d && odpytan + 3 < k && odpytan + 3 < 200 * d) { //typowanie wymiaru do rozważania int bestD = -1, maxWidth = 0; for (int i=0; i<d; i++) { if (max[i] - min[i] > maxWidth) { bestD = i; maxWidth = max[i] - min[i]; } } int firstAnswer, secondAnswer; answer[bestD] = min[bestD]; firstAnswer = czyCieplo(answer); answer[bestD] = max[bestD]; firstAnswer = czyCieplo(answer); answer[bestD] = min[bestD]; secondAnswer = czyCieplo(answer); //cout << "answers: " << firstAnswer << " " << secondAnswer << endl; if (firstAnswer == 0 && secondAnswer == 0) { int a = (max[bestD] + min[bestD]) / 2; if ((max[bestD] - min[bestD]) % 2 == 1) { if (a > 0) { min[bestD] = a-1; max[bestD] = a+1; } else { max[bestD] = a+2; min[bestD] = a; } } else { max[bestD] = a; min[bestD] = a; } } else if (firstAnswer == 1) { if ((max[bestD] - min[bestD])%2 == 1) min[bestD] = min[bestD] + (max[bestD] - min[bestD])/2; else min[bestD] = min[bestD] + (max[bestD] - min[bestD])/2 + 1; } else { if ((max[bestD] - min[bestD])%2 == 1) max[bestD] = min[bestD] + (max[bestD] - min[bestD])/2; else max[bestD] = min[bestD] + (max[bestD] - min[bestD])/2-1; } answer[bestD] = (max[bestD] + min[bestD]) / 2; if (max[bestD] == min[bestD]) ileSkonczonych++; odpytan += 3; } znalazlem(max); }
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 | #include "cielib.h" int main() { int d = podajD(); int k = podajK(); int r = podajR(); int ileSkonczonych = 0, odpytan = 0; int min[d], max[d], answer[d]; for (int i=0; i<d; i++) { min[i] = 0; max[i] = r; answer[i] = r/2; } while (ileSkonczonych != d && odpytan + 3 < k && odpytan + 3 < 200 * d) { //typowanie wymiaru do rozważania int bestD = -1, maxWidth = 0; for (int i=0; i<d; i++) { if (max[i] - min[i] > maxWidth) { bestD = i; maxWidth = max[i] - min[i]; } } int firstAnswer, secondAnswer; answer[bestD] = min[bestD]; firstAnswer = czyCieplo(answer); answer[bestD] = max[bestD]; firstAnswer = czyCieplo(answer); answer[bestD] = min[bestD]; secondAnswer = czyCieplo(answer); //cout << "answers: " << firstAnswer << " " << secondAnswer << endl; if (firstAnswer == 0 && secondAnswer == 0) { int a = (max[bestD] + min[bestD]) / 2; if ((max[bestD] - min[bestD]) % 2 == 1) { if (a > 0) { min[bestD] = a-1; max[bestD] = a+1; } else { max[bestD] = a+2; min[bestD] = a; } } else { max[bestD] = a; min[bestD] = a; } } else if (firstAnswer == 1) { if ((max[bestD] - min[bestD])%2 == 1) min[bestD] = min[bestD] + (max[bestD] - min[bestD])/2; else min[bestD] = min[bestD] + (max[bestD] - min[bestD])/2 + 1; } else { if ((max[bestD] - min[bestD])%2 == 1) max[bestD] = min[bestD] + (max[bestD] - min[bestD])/2; else max[bestD] = min[bestD] + (max[bestD] - min[bestD])/2-1; } answer[bestD] = (max[bestD] + min[bestD]) / 2; if (max[bestD] == min[bestD]) ileSkonczonych++; odpytan += 3; } znalazlem(max); } |