#include <bits/stdc++.h> using namespace std; struct farmer { int zloto; int x, y; }; vector<farmer> farmerzy; int kwadrat = 1; int plansza[20][20]; int budzet = 100; int zera = 0; int pelne_plecaki = 0; bool dod_zera[20][20]; //iint TEMP_KW = 1; void zlicz() { for(int i = 0; i < farmerzy.size(); i++) { farmer akt = farmerzy[i]; int x = akt.x; int y = akt.y; int podniesione = min(10, plansza[x][y]); plansza[x][y] -= podniesione; farmerzy[i].zloto += podniesione; if(dod_zera[x][y]) { zera++; dod_zera[x][y] = 0; } if(podniesione > 0 && farmerzy[i].zloto == podniesione) pelne_plecaki++; if(x == 0 && y == 0) { if(farmerzy[i].zloto > 0) { budzet += farmerzy[i].zloto; farmerzy[i].zloto = 0; pelne_plecaki--; } } if(podniesione > 0 && plansza[x][y] == 0) zera++; } } bool check[20][20]; int main() { ios_base::sync_with_stdio(0); //cin.tie(0); //cout.tie(0); int T, k; cin >> T >> k; for(int z = 0; z < T; z++) { kwadrat = 1; budzet = 100; zera = 0; pelne_plecaki = 0; farmerzy.clear(); int n; cin >> n; for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) { cin >> plansza[i][j]; if(plansza[i][j] == 0) dod_zera[i][j] = 1; } /*farmerzy.push_back({0, 0, 1}); farmerzy.push_back({32, 1, 1}); farmerzy.push_back({50, 0, 0}); zlicz(); for(int i = 0; i < farmerzy.size(); i++) cout << farmerzy[i].x << " " << farmerzy[i].y << " " << farmerzy[i].zloto << endl; cout << endl; for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) cout << plansza[i][j] << " "; cout << endl; }*/ cout << "R FARMER" << endl << "M 0 0 0 1" << endl << "=" << '\n'; farmerzy.push_back({0, 0, 1}); zlicz(); int war_koncowy = n * n; while(zera < war_koncowy || pelne_plecaki != 0) { //cout << "co kurla"; /*for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) cout << plansza[i][j] << " "; cout << endl; }*/ // cout << "zera" << zera << "pelne plecaki" << pelne_plecaki <<"kwadrack" << " " << kwadrat << "info o farmierach"; // for(int i = 0; i < farmerzy.size(); i++) // cout << farmerzy[i].x << " " << farmerzy[i].y << " " << farmerzy[i].zloto << ">>>>>>"; // cout << endl; int il_farm = farmerzy.size(); bool flag = 0; farmer temp = farmerzy[il_farm - 1]; if(budzet >= 100 && farmerzy[il_farm - 1].x == 0 && farmerzy[il_farm - 1].y == 1 && (farmerzy[0].x != 0 || farmerzy[0].y != 0) && (farmerzy[0].x != 1 || farmerzy[0].y != 0)) //sprawdz czy mamy wystarczajaco kasy , zeby kupic farmera, ostatni farmer jest na (0, 1) + czy potrzebuje farmera { flag = 1; budzet -= 100; farmerzy.push_back({0, 0, 1}); } for(int i = il_farm - 1; i >= 1; i--) { farmerzy[i].x = farmerzy[i - 1].x; farmerzy[i].y = farmerzy[i -1].y; //jeden za drugim } int xpierw = farmerzy[0].x; int ypierw = farmerzy[0].y; if(xpierw == 0 && ypierw == 0) (farmerzy[0].y)++; else if(xpierw == 0 && ypierw == kwadrat) (farmerzy[0].x)++; else if(xpierw == kwadrat && ypierw == kwadrat) (farmerzy[0].y)--; else if(xpierw == kwadrat && ypierw == 0) (farmerzy[0].x)--; else if(xpierw == 0) (farmerzy[0].y++); else if(ypierw == kwadrat) (farmerzy[0].x)++; else if(xpierw == kwadrat) (farmerzy[0].y)--; else (farmerzy[0].x)--; zlicz(); if(xpierw == 0 && ypierw == 0 && zera >= (kwadrat+1) * (kwadrat + 1) && kwadrat != n - 1) kwadrat++; for(int i = 0; i <= il_farm - 2; i++) cout << "M" << " " << farmerzy[i + 1].x << " " << farmerzy[i + 1].y << " " << farmerzy[i].x << " " << farmerzy[i].y << '\n'; cout << "M "<< " "<< temp.x << " " << temp.y << " " << farmerzy[il_farm - 1].x << " " << farmerzy[il_farm - 1].y << '\n'; if(flag) { cout << "R FARMER\n"; cout << "M" << " " << "0 0 0 1\n"; } //cout << "KWADRAT" << " " << kwadrat << " " << xpierw << " " << ypierw << endl; /*for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) cout << plansza[i][j] << " "; cout << endl; }*/ //cout << "GDZIE PINIONDZE" << budzet << endl; //cout << farmerzy.size() << endl; cout << "=" << '\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 | #include <bits/stdc++.h> using namespace std; struct farmer { int zloto; int x, y; }; vector<farmer> farmerzy; int kwadrat = 1; int plansza[20][20]; int budzet = 100; int zera = 0; int pelne_plecaki = 0; bool dod_zera[20][20]; //iint TEMP_KW = 1; void zlicz() { for(int i = 0; i < farmerzy.size(); i++) { farmer akt = farmerzy[i]; int x = akt.x; int y = akt.y; int podniesione = min(10, plansza[x][y]); plansza[x][y] -= podniesione; farmerzy[i].zloto += podniesione; if(dod_zera[x][y]) { zera++; dod_zera[x][y] = 0; } if(podniesione > 0 && farmerzy[i].zloto == podniesione) pelne_plecaki++; if(x == 0 && y == 0) { if(farmerzy[i].zloto > 0) { budzet += farmerzy[i].zloto; farmerzy[i].zloto = 0; pelne_plecaki--; } } if(podniesione > 0 && plansza[x][y] == 0) zera++; } } bool check[20][20]; int main() { ios_base::sync_with_stdio(0); //cin.tie(0); //cout.tie(0); int T, k; cin >> T >> k; for(int z = 0; z < T; z++) { kwadrat = 1; budzet = 100; zera = 0; pelne_plecaki = 0; farmerzy.clear(); int n; cin >> n; for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) { cin >> plansza[i][j]; if(plansza[i][j] == 0) dod_zera[i][j] = 1; } /*farmerzy.push_back({0, 0, 1}); farmerzy.push_back({32, 1, 1}); farmerzy.push_back({50, 0, 0}); zlicz(); for(int i = 0; i < farmerzy.size(); i++) cout << farmerzy[i].x << " " << farmerzy[i].y << " " << farmerzy[i].zloto << endl; cout << endl; for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) cout << plansza[i][j] << " "; cout << endl; }*/ cout << "R FARMER" << endl << "M 0 0 0 1" << endl << "=" << '\n'; farmerzy.push_back({0, 0, 1}); zlicz(); int war_koncowy = n * n; while(zera < war_koncowy || pelne_plecaki != 0) { //cout << "co kurla"; /*for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) cout << plansza[i][j] << " "; cout << endl; }*/ // cout << "zera" << zera << "pelne plecaki" << pelne_plecaki <<"kwadrack" << " " << kwadrat << "info o farmierach"; // for(int i = 0; i < farmerzy.size(); i++) // cout << farmerzy[i].x << " " << farmerzy[i].y << " " << farmerzy[i].zloto << ">>>>>>"; // cout << endl; int il_farm = farmerzy.size(); bool flag = 0; farmer temp = farmerzy[il_farm - 1]; if(budzet >= 100 && farmerzy[il_farm - 1].x == 0 && farmerzy[il_farm - 1].y == 1 && (farmerzy[0].x != 0 || farmerzy[0].y != 0) && (farmerzy[0].x != 1 || farmerzy[0].y != 0)) //sprawdz czy mamy wystarczajaco kasy , zeby kupic farmera, ostatni farmer jest na (0, 1) + czy potrzebuje farmera { flag = 1; budzet -= 100; farmerzy.push_back({0, 0, 1}); } for(int i = il_farm - 1; i >= 1; i--) { farmerzy[i].x = farmerzy[i - 1].x; farmerzy[i].y = farmerzy[i -1].y; //jeden za drugim } int xpierw = farmerzy[0].x; int ypierw = farmerzy[0].y; if(xpierw == 0 && ypierw == 0) (farmerzy[0].y)++; else if(xpierw == 0 && ypierw == kwadrat) (farmerzy[0].x)++; else if(xpierw == kwadrat && ypierw == kwadrat) (farmerzy[0].y)--; else if(xpierw == kwadrat && ypierw == 0) (farmerzy[0].x)--; else if(xpierw == 0) (farmerzy[0].y++); else if(ypierw == kwadrat) (farmerzy[0].x)++; else if(xpierw == kwadrat) (farmerzy[0].y)--; else (farmerzy[0].x)--; zlicz(); if(xpierw == 0 && ypierw == 0 && zera >= (kwadrat+1) * (kwadrat + 1) && kwadrat != n - 1) kwadrat++; for(int i = 0; i <= il_farm - 2; i++) cout << "M" << " " << farmerzy[i + 1].x << " " << farmerzy[i + 1].y << " " << farmerzy[i].x << " " << farmerzy[i].y << '\n'; cout << "M "<< " "<< temp.x << " " << temp.y << " " << farmerzy[il_farm - 1].x << " " << farmerzy[il_farm - 1].y << '\n'; if(flag) { cout << "R FARMER\n"; cout << "M" << " " << "0 0 0 1\n"; } //cout << "KWADRAT" << " " << kwadrat << " " << xpierw << " " << ypierw << endl; /*for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) cout << plansza[i][j] << " "; cout << endl; }*/ //cout << "GDZIE PINIONDZE" << budzet << endl; //cout << farmerzy.size() << endl; cout << "=" << '\n'; } cout << "===\n"; } } |