#include <iostream> #include <cstdio> using namespace std; const int N = 23; int n, t, d[N][N]; pair<int, int> pos[N]; int main() { scanf("%d%d", &t, &n); while(t--) { scanf("%d", &n); for(int i=0;i<n;i++) for(int j=0;j<n;j++) scanf("%d", &d[i][j]); printf("R FARMER\n"); printf("M 0 0 0 1\n"); printf("R FARMER\n"); printf("M 0 0 1 0\n"); int doz = (n - 2) * 100; pos[0] = make_pair(0, 1); pos[1] = make_pair(1, 0); doz -= min(d[0][1], 10); d[0][1]-=10; d[0][1] = max(0, d[0][1]); doz -= min(d[1][0], 10); d[1][0]-=10; d[1][0] = max(0, d[1][0]); printf("=\n"); while(doz > 0) { int x = pos[0].first, y = pos[0].second; if(d[x][y]) { doz -= min(d[x][y], 10); d[x][y]-=10; d[x][y] = max(0, d[x][y]); } else if(y!=n-1) { printf("M %d %d %d %d\n", x, y, x, y+1); y++; doz -= min(d[x][y], 10); d[x][y]-=10; d[x][y] = max(0, d[x][y]); } pos[0] = make_pair(x, y); x = pos[1].first, y = pos[1].second; if(d[x][y]) { doz -= min(d[x][y], 10); d[x][y]-=10; d[x][y] = max(0, d[x][y]); } else if(x!=n-1) { printf("M %d %d %d %d\n", x, y, x+1, y); x++; doz -= min(d[x][y], 10); d[x][y]-=10; d[x][y] = max(0, d[x][y]); } pos[1] = make_pair(x, y); printf("=\n"); } int il = pos[0].second; while(il--) { printf("M 0 %d 0 %d\n", il+1, il); pos[0].second--; if(pos[1].first!=1) { printf("M %d 0 %d 0\n", pos[1].first, pos[1].first - 1); pos[1].first--; } printf("=\n"); } while(pos[1].first!=1) { printf("M %d 0 %d 0\n", pos[1].first, pos[1].first - 1); pos[1].first--; printf("=\n"); } printf("M 0 0 0 1\n"); pos[0] = make_pair(0, 1); printf("M 1 0 0 0\n"); printf("=\n"); for(int i=0;i<n-2;i++) { for(int j=i+1;j>=0;j--) printf("M 0 %d 0 %d\n", j, j+1); printf("R FARMER\n"); printf("=\n"); } for(int i=0;i<n;i++) pos[i] = make_pair(0, i); int dok = 0; while(dok!=n) { for(int i=0;i<n;i++) { int x = pos[i].first; if(d[x][i]) { d[x][i]-=10; d[x][i] = max(0, d[x][i]); } else if(x!=n-1) { printf("M %d %d %d %d\n", x, i, x+1, i); x++; if(x==n-1) dok++; d[x][i]-=10; d[x][i] = max(0, d[x][i]); } pos[i].first = x; } printf("=\n"); } for(int i=n;i>0;i--) { for(int j=0;j<n;j++) printf("M %d %d %d %d\n", i, j, i-1, j); printf("=\n"); } for(int i=1;i<n;i++) { for(int j=i-1;j>=0;j--) printf("M %d %d %d %d\n", j, 0, j+1, 0); for(int j=1;j<=n-i;j++) printf("M %d %d %d %d\n", 0, j, 0, j-1); printf("=\n"); } printf("===\n"); } 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 | #include <iostream> #include <cstdio> using namespace std; const int N = 23; int n, t, d[N][N]; pair<int, int> pos[N]; int main() { scanf("%d%d", &t, &n); while(t--) { scanf("%d", &n); for(int i=0;i<n;i++) for(int j=0;j<n;j++) scanf("%d", &d[i][j]); printf("R FARMER\n"); printf("M 0 0 0 1\n"); printf("R FARMER\n"); printf("M 0 0 1 0\n"); int doz = (n - 2) * 100; pos[0] = make_pair(0, 1); pos[1] = make_pair(1, 0); doz -= min(d[0][1], 10); d[0][1]-=10; d[0][1] = max(0, d[0][1]); doz -= min(d[1][0], 10); d[1][0]-=10; d[1][0] = max(0, d[1][0]); printf("=\n"); while(doz > 0) { int x = pos[0].first, y = pos[0].second; if(d[x][y]) { doz -= min(d[x][y], 10); d[x][y]-=10; d[x][y] = max(0, d[x][y]); } else if(y!=n-1) { printf("M %d %d %d %d\n", x, y, x, y+1); y++; doz -= min(d[x][y], 10); d[x][y]-=10; d[x][y] = max(0, d[x][y]); } pos[0] = make_pair(x, y); x = pos[1].first, y = pos[1].second; if(d[x][y]) { doz -= min(d[x][y], 10); d[x][y]-=10; d[x][y] = max(0, d[x][y]); } else if(x!=n-1) { printf("M %d %d %d %d\n", x, y, x+1, y); x++; doz -= min(d[x][y], 10); d[x][y]-=10; d[x][y] = max(0, d[x][y]); } pos[1] = make_pair(x, y); printf("=\n"); } int il = pos[0].second; while(il--) { printf("M 0 %d 0 %d\n", il+1, il); pos[0].second--; if(pos[1].first!=1) { printf("M %d 0 %d 0\n", pos[1].first, pos[1].first - 1); pos[1].first--; } printf("=\n"); } while(pos[1].first!=1) { printf("M %d 0 %d 0\n", pos[1].first, pos[1].first - 1); pos[1].first--; printf("=\n"); } printf("M 0 0 0 1\n"); pos[0] = make_pair(0, 1); printf("M 1 0 0 0\n"); printf("=\n"); for(int i=0;i<n-2;i++) { for(int j=i+1;j>=0;j--) printf("M 0 %d 0 %d\n", j, j+1); printf("R FARMER\n"); printf("=\n"); } for(int i=0;i<n;i++) pos[i] = make_pair(0, i); int dok = 0; while(dok!=n) { for(int i=0;i<n;i++) { int x = pos[i].first; if(d[x][i]) { d[x][i]-=10; d[x][i] = max(0, d[x][i]); } else if(x!=n-1) { printf("M %d %d %d %d\n", x, i, x+1, i); x++; if(x==n-1) dok++; d[x][i]-=10; d[x][i] = max(0, d[x][i]); } pos[i].first = x; } printf("=\n"); } for(int i=n;i>0;i--) { for(int j=0;j<n;j++) printf("M %d %d %d %d\n", i, j, i-1, j); printf("=\n"); } for(int i=1;i<n;i++) { for(int j=i-1;j>=0;j--) printf("M %d %d %d %d\n", j, 0, j+1, 0); for(int j=1;j<=n-i;j++) printf("M %d %d %d %d\n", 0, j, 0, j-1); printf("=\n"); } printf("===\n"); } return 0; } |