#include <iostream> #include <vector> using namespace std; vector<pair<int, int> > spaceFillingCurve(int n) { vector<pair<int, int> > res; auto add = [&](int x, int y) { res.emplace_back(res.back().first + x, res.back().second + y); }; res.emplace_back(0,0); add(1, 0); for (int i=0; i < n/2; i ++) { for (int i=0; i < n-2; i++) add(1, 0); add(0, 1); for (int i=0; i < n-2; i++) add(-1, 0); if (i != n/2-1) add(0, 1); } add(-1, 0); for (int i=0; i < n-2; i++) add(0, -1); return res; } string ptos(pair<int, int> a) { return to_string(a.first) + " " + to_string(a.second); } void testcase() { int n; cin >> n; vector<vector<int> > game_map (n, vector<int> (n) ); for (auto&r:game_map)for(auto&i:r)cin>>i; auto curve = spaceFillingCurve(n); //for (auto& a:curve) cerr << "]] " << a.first << " " << a.second << endl; cout << "R FARMER" << "\n"; cout << "M 0 0 " << ptos(curve[1]) << "\n"; cout << "R FARMER" << "\n"; int count = 2; int L = curve.size(); int gold = 0; int rounds = 0; int fieldsLeft = n*n-1; int pos = 0; int countdown = L; auto nextRound = [&]() { cout << "=" << "\n"; rounds ++; for(int i=0; i < count; i ++) { auto farmerPos = curve[(pos + i) % L]; int& farmerField = game_map[farmerPos.first][farmerPos.second]; if (farmerField > 0) { gold += min(10, farmerField); farmerField -= min(10, farmerField); if (farmerField == 0) fieldsLeft --; } } }; auto countUnder = [&]() { int m =0; for(int i=0; i < count; i ++) { auto farmerPos = curve[(pos + i) % L]; int& farmerField = game_map[farmerPos.first][farmerPos.second]; if (farmerField > 0) { m = max(farmerField, m); } } return m; }; auto moveAll = [&](int delta) { if (delta == 1) { for(int i=count-1; i >= 0; i --) { cout << "M " << ptos(curve[(pos+i) % L]) << " " << ptos(curve[(pos+i+delta+L) % L]) << "\n"; } } else { for(int i=0; i < count; i ++) { cout << "M " << ptos(curve[(pos+i) % L]) << " " << ptos(curve[(pos+i+delta+L) % L]) << "\n"; } } pos += delta + L; pos %= L; }; while (countdown > 0) { int under = countUnder(); int turnsMore = (under / (count * 10)) - 1; nextRound(); moveAll(1); if (count < 50 && gold >= 200) { int startGold = gold; while(pos != L-count) { nextRound(); moveAll(-1); } while (startGold >= 100) { nextRound(); cout << "R FARMER" << "\n"; count ++; gold -= 100; startGold -= 100; moveAll(-1); } while(pos!=0) { nextRound(); moveAll(1); } } if (fieldsLeft == 0) countdown --; } cout << "===" << "\n"; } int main() { int T, k; cin >> T >> k; for (int i=0; i < T; i ++) testcase(); }
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 | #include <iostream> #include <vector> using namespace std; vector<pair<int, int> > spaceFillingCurve(int n) { vector<pair<int, int> > res; auto add = [&](int x, int y) { res.emplace_back(res.back().first + x, res.back().second + y); }; res.emplace_back(0,0); add(1, 0); for (int i=0; i < n/2; i ++) { for (int i=0; i < n-2; i++) add(1, 0); add(0, 1); for (int i=0; i < n-2; i++) add(-1, 0); if (i != n/2-1) add(0, 1); } add(-1, 0); for (int i=0; i < n-2; i++) add(0, -1); return res; } string ptos(pair<int, int> a) { return to_string(a.first) + " " + to_string(a.second); } void testcase() { int n; cin >> n; vector<vector<int> > game_map (n, vector<int> (n) ); for (auto&r:game_map)for(auto&i:r)cin>>i; auto curve = spaceFillingCurve(n); //for (auto& a:curve) cerr << "]] " << a.first << " " << a.second << endl; cout << "R FARMER" << "\n"; cout << "M 0 0 " << ptos(curve[1]) << "\n"; cout << "R FARMER" << "\n"; int count = 2; int L = curve.size(); int gold = 0; int rounds = 0; int fieldsLeft = n*n-1; int pos = 0; int countdown = L; auto nextRound = [&]() { cout << "=" << "\n"; rounds ++; for(int i=0; i < count; i ++) { auto farmerPos = curve[(pos + i) % L]; int& farmerField = game_map[farmerPos.first][farmerPos.second]; if (farmerField > 0) { gold += min(10, farmerField); farmerField -= min(10, farmerField); if (farmerField == 0) fieldsLeft --; } } }; auto countUnder = [&]() { int m =0; for(int i=0; i < count; i ++) { auto farmerPos = curve[(pos + i) % L]; int& farmerField = game_map[farmerPos.first][farmerPos.second]; if (farmerField > 0) { m = max(farmerField, m); } } return m; }; auto moveAll = [&](int delta) { if (delta == 1) { for(int i=count-1; i >= 0; i --) { cout << "M " << ptos(curve[(pos+i) % L]) << " " << ptos(curve[(pos+i+delta+L) % L]) << "\n"; } } else { for(int i=0; i < count; i ++) { cout << "M " << ptos(curve[(pos+i) % L]) << " " << ptos(curve[(pos+i+delta+L) % L]) << "\n"; } } pos += delta + L; pos %= L; }; while (countdown > 0) { int under = countUnder(); int turnsMore = (under / (count * 10)) - 1; nextRound(); moveAll(1); if (count < 50 && gold >= 200) { int startGold = gold; while(pos != L-count) { nextRound(); moveAll(-1); } while (startGold >= 100) { nextRound(); cout << "R FARMER" << "\n"; count ++; gold -= 100; startGold -= 100; moveAll(-1); } while(pos!=0) { nextRound(); moveAll(1); } } if (fieldsLeft == 0) countdown --; } cout << "===" << "\n"; } int main() { int T, k; cin >> T >> k; for (int i=0; i < T; i ++) testcase(); } |