// Grzegorz Bukowiec // Potyczki Algorytmiczne 2018 // Runda 5B - Gra #include <iostream> #include <vector> using namespace std; void endTurn() { cout << "=" << endl; } void endGame() { cout << "===" << endl; } void move(int x1, int y1, int x2, int y2) { cout << "M " << x1 << " " << y1 << " " << x2 << " " << y2 << endl; } void buyFarmer() { cout << "R FARMER" << endl; } struct Game { int n; int board[20][20]; bool tank; long long goldOverall; long long money; long long moneySpent; vector<int> bags; int firstFarmer; int lastFarmer; vector<pair<int, int>> path; Game(int size) { n = size; tank = false; money = 200; moneySpent = 0; goldOverall = 0; firstFarmer = 0; lastFarmer = -1; path.push_back(make_pair(0, 0)); for (int i = 0; i < n; ++i) { if (i % 2) { for (int j = n - 1; j > 0; --j) { path.push_back(make_pair(i, j)); } } else { for (int j = 1; j < n; ++j) { path.push_back(make_pair(i, j)); } } } for (int i = n - 1; i >= 1; --i) { path.push_back(make_pair(i, 0)); } } void setBoard(int x, int y, int val) { board[x][y] = val; goldOverall += val; } void tryBuying() { if (money >= 100 && lastFarmer != 0 && lastFarmer <= firstFarmer) { buyFarmer(); money -= 100; moneySpent += 100; lastFarmer = 0; bags.push_back(0); } } void collect(int k, int x, int y) { if (board[x][y] >= 10) { board[x][y] -= 10; bags[k] += 10; } else if (board[x][y] > 0) { bags[k] += board[x][y]; board[x][y] = 0; } } void giveBack(int k, int x, int y) { if (x == 0 && y == 0) { money += bags[k]; bags[k] = 0; } } void moveAll() { ++firstFarmer; if (firstFarmer == n * n) { firstFarmer = 0; } ++lastFarmer; if (lastFarmer == n * n) { lastFarmer = 0; } int k = 0; int field = lastFarmer; if (lastFarmer <= firstFarmer) { while (field <= firstFarmer) { if (field) { move(path[field - 1].first, path[field - 1].second, path[field].first, path[field].second); } else { move(path[n * n - 1].first, path[n * n - 1].second, path[0].first, path[0].second); } collect(k, path[field].first, path[field].second); giveBack(k, path[field].first, path[field].second); ++k; ++field; } } else { while (field < n * n) { if (field) { move(path[field - 1].first, path[field - 1].second, path[field].first, path[field].second); } else { move(path[n * n - 1].first, path[n * n - 1].second, path[0].first, path[0].second); } collect(k, path[field].first, path[field].second); giveBack(k, path[field].first, path[field].second); ++k; ++field; } field = 0; while (field <= firstFarmer) { if (field) { move(path[field - 1].first, path[field - 1].second, path[field].first, path[field].second); } else { move(path[n * n - 1].first, path[n * n - 1].second, path[0].first, path[0].second); } collect(k, path[field].first, path[field].second); giveBack(k, path[field].first, path[field].second); ++k; ++field; } } } }; int main() { int z, k; cin >> z; cin >> k; while (z--) { int n, a; cin >> n; Game game(n); for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { cin >> a; game.setBoard(i, j, a); } } while (game.goldOverall > game.moneySpent + game.money - 200) { game.tryBuying(); game.moveAll(); endTurn(); } endGame(); } 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 169 170 171 172 173 174 | // Grzegorz Bukowiec // Potyczki Algorytmiczne 2018 // Runda 5B - Gra #include <iostream> #include <vector> using namespace std; void endTurn() { cout << "=" << endl; } void endGame() { cout << "===" << endl; } void move(int x1, int y1, int x2, int y2) { cout << "M " << x1 << " " << y1 << " " << x2 << " " << y2 << endl; } void buyFarmer() { cout << "R FARMER" << endl; } struct Game { int n; int board[20][20]; bool tank; long long goldOverall; long long money; long long moneySpent; vector<int> bags; int firstFarmer; int lastFarmer; vector<pair<int, int>> path; Game(int size) { n = size; tank = false; money = 200; moneySpent = 0; goldOverall = 0; firstFarmer = 0; lastFarmer = -1; path.push_back(make_pair(0, 0)); for (int i = 0; i < n; ++i) { if (i % 2) { for (int j = n - 1; j > 0; --j) { path.push_back(make_pair(i, j)); } } else { for (int j = 1; j < n; ++j) { path.push_back(make_pair(i, j)); } } } for (int i = n - 1; i >= 1; --i) { path.push_back(make_pair(i, 0)); } } void setBoard(int x, int y, int val) { board[x][y] = val; goldOverall += val; } void tryBuying() { if (money >= 100 && lastFarmer != 0 && lastFarmer <= firstFarmer) { buyFarmer(); money -= 100; moneySpent += 100; lastFarmer = 0; bags.push_back(0); } } void collect(int k, int x, int y) { if (board[x][y] >= 10) { board[x][y] -= 10; bags[k] += 10; } else if (board[x][y] > 0) { bags[k] += board[x][y]; board[x][y] = 0; } } void giveBack(int k, int x, int y) { if (x == 0 && y == 0) { money += bags[k]; bags[k] = 0; } } void moveAll() { ++firstFarmer; if (firstFarmer == n * n) { firstFarmer = 0; } ++lastFarmer; if (lastFarmer == n * n) { lastFarmer = 0; } int k = 0; int field = lastFarmer; if (lastFarmer <= firstFarmer) { while (field <= firstFarmer) { if (field) { move(path[field - 1].first, path[field - 1].second, path[field].first, path[field].second); } else { move(path[n * n - 1].first, path[n * n - 1].second, path[0].first, path[0].second); } collect(k, path[field].first, path[field].second); giveBack(k, path[field].first, path[field].second); ++k; ++field; } } else { while (field < n * n) { if (field) { move(path[field - 1].first, path[field - 1].second, path[field].first, path[field].second); } else { move(path[n * n - 1].first, path[n * n - 1].second, path[0].first, path[0].second); } collect(k, path[field].first, path[field].second); giveBack(k, path[field].first, path[field].second); ++k; ++field; } field = 0; while (field <= firstFarmer) { if (field) { move(path[field - 1].first, path[field - 1].second, path[field].first, path[field].second); } else { move(path[n * n - 1].first, path[n * n - 1].second, path[0].first, path[0].second); } collect(k, path[field].first, path[field].second); giveBack(k, path[field].first, path[field].second); ++k; ++field; } } } }; int main() { int z, k; cin >> z; cin >> k; while (z--) { int n, a; cin >> n; Game game(n); for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { cin >> a; game.setBoard(i, j, a); } } while (game.goldOverall > game.moneySpent + game.money - 200) { game.tryBuying(); game.moveAll(); endTurn(); } endGame(); } return 0; } |