#include<bits/stdc++.h> #define s second #define f first using namespace std; int useless,kamolce,zapy,zloto,n,m,rep[1000005],ilosc,reprez,x,wynik,xczolg,yczolg,xfarmer,yfarmer,t[25][25]; void ruch1() { if(xczolg==1&&yczolg==n-1)return; else if(xczolg==n-1&&yczolg%4==2) { cout<<"M "<<xczolg-1<<' '<<yczolg-1<<' '<<xczolg-1<<' '<<yczolg<<'\n'; yczolg++; } else if(yczolg%4==2) { cout<<"M "<<xczolg-1<<' '<<yczolg-1<<' '<<xczolg<<' '<<yczolg-1<<'\n'; xczolg++; } else if(xczolg==1) { cout<<"M "<<xczolg-1<<' '<<yczolg-1<<' '<<xczolg-1<<' '<<yczolg<<'\n'; yczolg++; } else { cout<<"M "<<xczolg-1<<' '<<yczolg-1<<' '<<xczolg-2<<' '<<yczolg-1<<'\n'; xczolg--; } } void ruch2() { if(xfarmer==1&&yfarmer==n)return; else if(xfarmer==2&&yfarmer==n) { cout<<"M "<<xfarmer-1<<' '<<yfarmer-1<<' '<<xfarmer-2<<' '<<yfarmer-1<<'\n'; xfarmer--; } else if(xfarmer==2&&yfarmer%4==0) { cout<<"M "<<xfarmer-1<<' '<<yfarmer-1<<' '<<xfarmer-1<<' '<<yfarmer<<'\n'; yfarmer++; } else if(yfarmer%4==0) { cout<<"M "<<xfarmer-1<<' '<<yfarmer-1<<' '<<xfarmer-2<<' '<<yfarmer-1<<'\n'; xfarmer--; } else if(xfarmer==n) { cout<<"M "<<xfarmer-1<<' '<<yfarmer-1<<' '<<xfarmer-1<<' '<<yfarmer<<'\n'; yfarmer++; } else { cout<<"M "<<xfarmer-1<<' '<<yfarmer-1<<' '<<xfarmer<<' '<<yfarmer-1<<'\n'; xfarmer++; } } void ruch3() { if(xczolg==n&&yczolg==1)return; else if(yczolg==1&&xczolg%2==0) { cout<<"M "<<xczolg-1<<' '<<yczolg-1<<' '<<xczolg<<' '<<yczolg-1<<'\n'; xczolg++; } else if(yczolg==1) { cout<<"M "<<xczolg-1<<' '<<yczolg-1<<' '<<xczolg-1<<' '<<yczolg<<'\n'; yczolg++; } else if(yczolg==n&&xczolg%2==0) { cout<<"M "<<xczolg-1<<' '<<yczolg-1<<' '<<xczolg-1<<' '<<yczolg-2<<'\n'; yczolg--; } else if(yczolg==n) { cout<<"M "<<xczolg-1<<' '<<yczolg-1<<' '<<xczolg<<' '<<yczolg-1<<'\n'; xczolg++; } else if(xczolg%2==0) { cout<<"M "<<xczolg-1<<' '<<yczolg-1<<' '<<xczolg-1<<' '<<yczolg-2<<'\n'; yczolg--; } else if(xczolg%2==1) { cout<<"M "<<xczolg-1<<' '<<yczolg-1<<' '<<xczolg-1<<' '<<yczolg<<'\n'; yczolg++; } } void ruch4() { if(xfarmer==n&&yfarmer==2)return; else if(yfarmer==1&&xfarmer%2==0) { if(xfarmer+1==xczolg&&yfarmer==yczolg)return; cout<<"M "<<xfarmer-1<<' '<<yfarmer-1<<' '<<xfarmer<<' '<<yfarmer-1<<'\n'; xfarmer++; } else if(yfarmer==1) { if(xfarmer==xczolg&&yfarmer+1==yczolg)return; cout<<"M "<<xfarmer-1<<' '<<yfarmer-1<<' '<<xfarmer-1<<' '<<yfarmer<<'\n'; yfarmer++; } else if(yfarmer==n&&xfarmer%2==0) { if(xfarmer==xczolg&&yfarmer-1==yczolg)return; cout<<"M "<<xfarmer-1<<' '<<yfarmer-1<<' '<<xfarmer-1<<' '<<yfarmer-2<<'\n'; yfarmer--; } else if(yfarmer==n) { if(xfarmer+1==xczolg&&yfarmer==yczolg)return; cout<<"M "<<xfarmer-1<<' '<<yfarmer-1<<' '<<xfarmer<<' '<<yfarmer-1<<'\n'; xfarmer++; } else if(xfarmer%2==0) { if(xfarmer==xczolg&&yfarmer-1==yczolg)return; cout<<"M "<<xfarmer-1<<' '<<yfarmer-1<<' '<<xfarmer-1<<' '<<yfarmer-2<<'\n'; yfarmer--; } else if(xfarmer%2==1) { if(xfarmer==xczolg&&yfarmer+1==yczolg)return; cout<<"M "<<xfarmer-1<<' '<<yfarmer-1<<' '<<xfarmer-1<<' '<<yfarmer<<'\n'; yfarmer++; } } int main() { ios_base::sync_with_stdio(0); cin>>zapy>>useless; while(zapy--) { cin>>n; kamolce=0; for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { cin>>t[i][j]; if(t[i][j]<0){kamolce=1;} } } if(kamolce==0) { cout<<"R FARMER"<<'\n'; cout<<"M 0 0 0 1"<<'\n'; cout<<"R FARMER"<<'\n'; cout<<'='<<'\n'; if(t[1][2]>0){t[1][2]-=10;if(t[1][2]<0)t[1][2]=0;} xczolg=1; xfarmer=1; yczolg=2; yfarmer=1; while(1) { if(t[xczolg][yczolg]==0)ruch1(); if(t[xfarmer][yfarmer]==0)ruch2(); t[xczolg][yczolg]-=10;if(t[xczolg][yczolg]<0)t[xczolg][yczolg]=0; t[xfarmer][yfarmer]-=10;if(t[xfarmer][yfarmer]<0)t[xfarmer][yfarmer]=0; cout<<'='<<'\n'; if(xczolg==1&&yczolg==n-1&&xfarmer==1&&yfarmer==n&&t[xczolg][yczolg]==0&&t[xfarmer][yfarmer]==0)break; } for(int i=n-1;i>1;i--)cout<<"M 0 "<<i-1<<" 0 "<<i-2<<'\n'<<"M 0 "<<i<<" 0 "<<i-1<<'\n'<<'='<<'\n'; cout<<"M 0 0 1 0"<<'\n'<<"M 0 1 0 0 "<<'\n'<<'='<<'\n'; cout<<"==="<<'\n'; } else { cout<<"R TANK"<<'\n'; cout<<"M 0 0 0 1"<<'\n'; cout<<"R FARMER"<<'\n'; cout<<'='<<'\n'; if(t[1][2]<0){t[1][2]+=10;if(t[1][2]>0)t[1][2]=0;} xczolg=1; xfarmer=1; yczolg=2; yfarmer=1; while(1) { if(t[xczolg][yczolg]>=0)ruch3(); if(t[xfarmer][yfarmer]==0)ruch4(); if(t[xczolg][yczolg]<0)t[xczolg][yczolg]+=min(-t[xczolg][yczolg],10); if(t[xfarmer][yfarmer]>0)t[xfarmer][yfarmer]-=min(t[xfarmer][yfarmer],10); cout<<'='<<'\n'; if(xczolg==n&&yczolg==1&&xfarmer==n&&yfarmer==2&&t[xczolg][yczolg]>=0&&t[xfarmer][yfarmer]==0)break; } cout<<"M "<<n-1<<" 0 "<<n-2<<" 0"<<'\n'<<"M "<<n-1<<" 1 "<<n-1<<" 0"<<'\n'<<'='<<'\n'; t[n][1]-=10; while(t[n][1]>0){cout<<'='<<'\n';t[n][1]-=10;} for(int i=n-1;i>1;i--)cout<<"M "<<i-1<<" 0 "<<i-2<<" 0"<<'\n'<<"M "<<i<<" 0 "<<i-1<<" 0"<<'\n'<<'='<<'\n'; cout<<"M 0 0 0 1"<<'\n'<<"M 1 0 0 0 "<<'\n'<<'='<<'\n'; cout<<"==="<<'\n'; } } }
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 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | #include<bits/stdc++.h> #define s second #define f first using namespace std; int useless,kamolce,zapy,zloto,n,m,rep[1000005],ilosc,reprez,x,wynik,xczolg,yczolg,xfarmer,yfarmer,t[25][25]; void ruch1() { if(xczolg==1&&yczolg==n-1)return; else if(xczolg==n-1&&yczolg%4==2) { cout<<"M "<<xczolg-1<<' '<<yczolg-1<<' '<<xczolg-1<<' '<<yczolg<<'\n'; yczolg++; } else if(yczolg%4==2) { cout<<"M "<<xczolg-1<<' '<<yczolg-1<<' '<<xczolg<<' '<<yczolg-1<<'\n'; xczolg++; } else if(xczolg==1) { cout<<"M "<<xczolg-1<<' '<<yczolg-1<<' '<<xczolg-1<<' '<<yczolg<<'\n'; yczolg++; } else { cout<<"M "<<xczolg-1<<' '<<yczolg-1<<' '<<xczolg-2<<' '<<yczolg-1<<'\n'; xczolg--; } } void ruch2() { if(xfarmer==1&&yfarmer==n)return; else if(xfarmer==2&&yfarmer==n) { cout<<"M "<<xfarmer-1<<' '<<yfarmer-1<<' '<<xfarmer-2<<' '<<yfarmer-1<<'\n'; xfarmer--; } else if(xfarmer==2&&yfarmer%4==0) { cout<<"M "<<xfarmer-1<<' '<<yfarmer-1<<' '<<xfarmer-1<<' '<<yfarmer<<'\n'; yfarmer++; } else if(yfarmer%4==0) { cout<<"M "<<xfarmer-1<<' '<<yfarmer-1<<' '<<xfarmer-2<<' '<<yfarmer-1<<'\n'; xfarmer--; } else if(xfarmer==n) { cout<<"M "<<xfarmer-1<<' '<<yfarmer-1<<' '<<xfarmer-1<<' '<<yfarmer<<'\n'; yfarmer++; } else { cout<<"M "<<xfarmer-1<<' '<<yfarmer-1<<' '<<xfarmer<<' '<<yfarmer-1<<'\n'; xfarmer++; } } void ruch3() { if(xczolg==n&&yczolg==1)return; else if(yczolg==1&&xczolg%2==0) { cout<<"M "<<xczolg-1<<' '<<yczolg-1<<' '<<xczolg<<' '<<yczolg-1<<'\n'; xczolg++; } else if(yczolg==1) { cout<<"M "<<xczolg-1<<' '<<yczolg-1<<' '<<xczolg-1<<' '<<yczolg<<'\n'; yczolg++; } else if(yczolg==n&&xczolg%2==0) { cout<<"M "<<xczolg-1<<' '<<yczolg-1<<' '<<xczolg-1<<' '<<yczolg-2<<'\n'; yczolg--; } else if(yczolg==n) { cout<<"M "<<xczolg-1<<' '<<yczolg-1<<' '<<xczolg<<' '<<yczolg-1<<'\n'; xczolg++; } else if(xczolg%2==0) { cout<<"M "<<xczolg-1<<' '<<yczolg-1<<' '<<xczolg-1<<' '<<yczolg-2<<'\n'; yczolg--; } else if(xczolg%2==1) { cout<<"M "<<xczolg-1<<' '<<yczolg-1<<' '<<xczolg-1<<' '<<yczolg<<'\n'; yczolg++; } } void ruch4() { if(xfarmer==n&&yfarmer==2)return; else if(yfarmer==1&&xfarmer%2==0) { if(xfarmer+1==xczolg&&yfarmer==yczolg)return; cout<<"M "<<xfarmer-1<<' '<<yfarmer-1<<' '<<xfarmer<<' '<<yfarmer-1<<'\n'; xfarmer++; } else if(yfarmer==1) { if(xfarmer==xczolg&&yfarmer+1==yczolg)return; cout<<"M "<<xfarmer-1<<' '<<yfarmer-1<<' '<<xfarmer-1<<' '<<yfarmer<<'\n'; yfarmer++; } else if(yfarmer==n&&xfarmer%2==0) { if(xfarmer==xczolg&&yfarmer-1==yczolg)return; cout<<"M "<<xfarmer-1<<' '<<yfarmer-1<<' '<<xfarmer-1<<' '<<yfarmer-2<<'\n'; yfarmer--; } else if(yfarmer==n) { if(xfarmer+1==xczolg&&yfarmer==yczolg)return; cout<<"M "<<xfarmer-1<<' '<<yfarmer-1<<' '<<xfarmer<<' '<<yfarmer-1<<'\n'; xfarmer++; } else if(xfarmer%2==0) { if(xfarmer==xczolg&&yfarmer-1==yczolg)return; cout<<"M "<<xfarmer-1<<' '<<yfarmer-1<<' '<<xfarmer-1<<' '<<yfarmer-2<<'\n'; yfarmer--; } else if(xfarmer%2==1) { if(xfarmer==xczolg&&yfarmer+1==yczolg)return; cout<<"M "<<xfarmer-1<<' '<<yfarmer-1<<' '<<xfarmer-1<<' '<<yfarmer<<'\n'; yfarmer++; } } int main() { ios_base::sync_with_stdio(0); cin>>zapy>>useless; while(zapy--) { cin>>n; kamolce=0; for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { cin>>t[i][j]; if(t[i][j]<0){kamolce=1;} } } if(kamolce==0) { cout<<"R FARMER"<<'\n'; cout<<"M 0 0 0 1"<<'\n'; cout<<"R FARMER"<<'\n'; cout<<'='<<'\n'; if(t[1][2]>0){t[1][2]-=10;if(t[1][2]<0)t[1][2]=0;} xczolg=1; xfarmer=1; yczolg=2; yfarmer=1; while(1) { if(t[xczolg][yczolg]==0)ruch1(); if(t[xfarmer][yfarmer]==0)ruch2(); t[xczolg][yczolg]-=10;if(t[xczolg][yczolg]<0)t[xczolg][yczolg]=0; t[xfarmer][yfarmer]-=10;if(t[xfarmer][yfarmer]<0)t[xfarmer][yfarmer]=0; cout<<'='<<'\n'; if(xczolg==1&&yczolg==n-1&&xfarmer==1&&yfarmer==n&&t[xczolg][yczolg]==0&&t[xfarmer][yfarmer]==0)break; } for(int i=n-1;i>1;i--)cout<<"M 0 "<<i-1<<" 0 "<<i-2<<'\n'<<"M 0 "<<i<<" 0 "<<i-1<<'\n'<<'='<<'\n'; cout<<"M 0 0 1 0"<<'\n'<<"M 0 1 0 0 "<<'\n'<<'='<<'\n'; cout<<"==="<<'\n'; } else { cout<<"R TANK"<<'\n'; cout<<"M 0 0 0 1"<<'\n'; cout<<"R FARMER"<<'\n'; cout<<'='<<'\n'; if(t[1][2]<0){t[1][2]+=10;if(t[1][2]>0)t[1][2]=0;} xczolg=1; xfarmer=1; yczolg=2; yfarmer=1; while(1) { if(t[xczolg][yczolg]>=0)ruch3(); if(t[xfarmer][yfarmer]==0)ruch4(); if(t[xczolg][yczolg]<0)t[xczolg][yczolg]+=min(-t[xczolg][yczolg],10); if(t[xfarmer][yfarmer]>0)t[xfarmer][yfarmer]-=min(t[xfarmer][yfarmer],10); cout<<'='<<'\n'; if(xczolg==n&&yczolg==1&&xfarmer==n&&yfarmer==2&&t[xczolg][yczolg]>=0&&t[xfarmer][yfarmer]==0)break; } cout<<"M "<<n-1<<" 0 "<<n-2<<" 0"<<'\n'<<"M "<<n-1<<" 1 "<<n-1<<" 0"<<'\n'<<'='<<'\n'; t[n][1]-=10; while(t[n][1]>0){cout<<'='<<'\n';t[n][1]-=10;} for(int i=n-1;i>1;i--)cout<<"M "<<i-1<<" 0 "<<i-2<<" 0"<<'\n'<<"M "<<i<<" 0 "<<i-1<<" 0"<<'\n'<<'='<<'\n'; cout<<"M 0 0 0 1"<<'\n'<<"M 1 0 0 0 "<<'\n'<<'='<<'\n'; cout<<"==="<<'\n'; } } } |