//Pawel Kura, zadanie Cieplo-zimno #include <bits/stdc++.h> #include "cielib.h" using namespace std; const int MAXD = 500; int D, K, R; int a[MAXD]; int cCieplo(int *x) { return czyCieplo(x); } bool cieplej(int *x, int i, int d, bool ref = true) { if (ref) cCieplo(x); x[i] += d; int r = cCieplo(x); x[i] -= d; return r == 1; } bool zimniej(int *x, int i, int d, bool ref = true) { x[i] += d; if (ref) cCieplo(x); x[i] -= d; int r = cCieplo(x); return r == 1; } bool sprawdz(int *x) { if (x[0] == 0) { return zimniej(x, 0, 1); } if (x[0] == R) { return zimniej(x, 0, -1); } return zimniej(x, 0, -1) && zimniej(x, 0, 1); } int main() { D = podajD(); K = podajK(); R = podajR(); int p1 = 0; int p2 = 0; int iter = 0; int from[MAXD], to[MAXD], mid[MAXD]; for (int i = 0; i < D; i++) { from[i] = 0; to[i] = R; } while (1) { for (int i = 0; i < D; i++) { a[i] = (from[i] + to[i]) / 2; } for (int i = 0; i < D; i++) { if (from[i] == to[i]) continue; int m = a[i]; a[i] = from[i]; czyCieplo(a); a[i] = to[i]; int p = czyCieplo(a); if (p == 0) { a[i] = from[i]; p = czyCieplo(a); p = -p; } if (p == 1) { from[i] = m + 1; } else if (p == -1) { to[i] = m; } else { from[i] = to[i] = m; } a[i] = (from[i] + to[i])/2; } int s = 0; for (int i = 0; i < D; i++) { //cerr << i << ": " << from [i] << " " << to[i] << "\n"; s += to[i] - from[i]; } //cerr <<"\n"; for (int i = 0; i < D; i++) { //cerr << a[i] << " "; } //cerr <<"\n"; if (s == 0) { for (int i = 0; i < D; i++) { if (a[i] > 0 && a[i] < R) { int p = zimniej(a, i, -1); int r = zimniej(a, i, 1); if (p && r) continue; if (p) a[i]++; if (r) a[i]--; continue; } if (a[i] == 0) { if (cieplej(a, i, 1)) { a[i]++; continue; } if (zimniej(a, i, 1)) { continue; } if (!zimniej(a, i, 2)) { a[i]++; } continue; } if (a[i] == R) { if (cieplej(a, i, -1)) { a[i]--; continue; } if (zimniej(a, i, -1)) { continue; } if (!zimniej(a, i, -2)) { a[i]--; } continue; } } } if (sprawdz(a)) { znalazlem(a); break; } if (s==0) { cerr << "ZONK\n"; break; } } 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 | //Pawel Kura, zadanie Cieplo-zimno #include <bits/stdc++.h> #include "cielib.h" using namespace std; const int MAXD = 500; int D, K, R; int a[MAXD]; int cCieplo(int *x) { return czyCieplo(x); } bool cieplej(int *x, int i, int d, bool ref = true) { if (ref) cCieplo(x); x[i] += d; int r = cCieplo(x); x[i] -= d; return r == 1; } bool zimniej(int *x, int i, int d, bool ref = true) { x[i] += d; if (ref) cCieplo(x); x[i] -= d; int r = cCieplo(x); return r == 1; } bool sprawdz(int *x) { if (x[0] == 0) { return zimniej(x, 0, 1); } if (x[0] == R) { return zimniej(x, 0, -1); } return zimniej(x, 0, -1) && zimniej(x, 0, 1); } int main() { D = podajD(); K = podajK(); R = podajR(); int p1 = 0; int p2 = 0; int iter = 0; int from[MAXD], to[MAXD], mid[MAXD]; for (int i = 0; i < D; i++) { from[i] = 0; to[i] = R; } while (1) { for (int i = 0; i < D; i++) { a[i] = (from[i] + to[i]) / 2; } for (int i = 0; i < D; i++) { if (from[i] == to[i]) continue; int m = a[i]; a[i] = from[i]; czyCieplo(a); a[i] = to[i]; int p = czyCieplo(a); if (p == 0) { a[i] = from[i]; p = czyCieplo(a); p = -p; } if (p == 1) { from[i] = m + 1; } else if (p == -1) { to[i] = m; } else { from[i] = to[i] = m; } a[i] = (from[i] + to[i])/2; } int s = 0; for (int i = 0; i < D; i++) { //cerr << i << ": " << from [i] << " " << to[i] << "\n"; s += to[i] - from[i]; } //cerr <<"\n"; for (int i = 0; i < D; i++) { //cerr << a[i] << " "; } //cerr <<"\n"; if (s == 0) { for (int i = 0; i < D; i++) { if (a[i] > 0 && a[i] < R) { int p = zimniej(a, i, -1); int r = zimniej(a, i, 1); if (p && r) continue; if (p) a[i]++; if (r) a[i]--; continue; } if (a[i] == 0) { if (cieplej(a, i, 1)) { a[i]++; continue; } if (zimniej(a, i, 1)) { continue; } if (!zimniej(a, i, 2)) { a[i]++; } continue; } if (a[i] == R) { if (cieplej(a, i, -1)) { a[i]--; continue; } if (zimniej(a, i, -1)) { continue; } if (!zimniej(a, i, -2)) { a[i]--; } continue; } } } if (sprawdz(a)) { znalazlem(a); break; } if (s==0) { cerr << "ZONK\n"; break; } } return 0; } |