#include <iostream> #include <cstdio> #include "osalib.h" using namespace std; int N, M, Osady; char Board[1005][1005]; int BFS[1005][1005]; int BFSx[1000005]; int BFSy[1000005]; void NowaWyspa(int n, int m, char **board) { N = n; M = m; Osady = 0; for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) { Board[i][j] = board[i - 1][j - 1]; if (Board[i][j] == 'K') Osady++; } } int NowaWarownia(int r, int c) { Board[r][c] = 'W'; if (Osady < 2) return 1; for (int i = 1; i <= N; ++i) for (int j = 1; j <= M; ++j) BFS[i][j] = 0; bool czy = 0; for (int i = 1; i <= N; ++i) { for (int j = 1; j <= M; ++j) { if (Board[i][j] == 'K') { BFS[i][j] = 1; BFSx[0] = i; BFSy[0] = j; czy = 1; break; } } if (czy) break; } int b = 0; int e = 1; int osady = 1; while (b < e) { int x = BFSx[b]; int y = BFSy[b]; if (x > 1 && Board[x - 1][y] != 'W' && BFS[x - 1][y] == 0) { BFSx[e] = x - 1; BFSy[e] = y; BFS[x - 1][y] = 1; if (Board[x - 1][y] == 'K') osady++; e++; } if (y > 1 && Board[x][y - 1] != 'W' && BFS[x][y - 1] == 0) { BFSx[e] = x; BFSy[e] = y - 1; BFS[x][y - 1] = 1; if (Board[x][y - 1] == 'K') osady++; e++; } if (x < N && Board[x + 1][y] != 'W' && BFS[x + 1][y] == 0) { BFSx[e] = x + 1; BFSy[e] = y; BFS[x + 1][y] = 1; if (Board[x + 1][y] == 'K') osady++; e++; } if (y < M && Board[x][y + 1] != 'W' && BFS[x][y + 1] == 0) { BFSx[e] = x; BFSy[e] = y + 1; BFS[x][y + 1] = 1; if (Board[x][y + 1] == 'K') osady++; e++; } b++; } if (osady == Osady) return 1; Board[r][c] = '.'; return 0; } void PrzeniesOsade(int r1, int c1, int r2, int c2) { Board[r2][c2] = 'K'; Board[r1][c1] = '.'; } /*int main () { 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 | #include <iostream> #include <cstdio> #include "osalib.h" using namespace std; int N, M, Osady; char Board[1005][1005]; int BFS[1005][1005]; int BFSx[1000005]; int BFSy[1000005]; void NowaWyspa(int n, int m, char **board) { N = n; M = m; Osady = 0; for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) { Board[i][j] = board[i - 1][j - 1]; if (Board[i][j] == 'K') Osady++; } } int NowaWarownia(int r, int c) { Board[r][c] = 'W'; if (Osady < 2) return 1; for (int i = 1; i <= N; ++i) for (int j = 1; j <= M; ++j) BFS[i][j] = 0; bool czy = 0; for (int i = 1; i <= N; ++i) { for (int j = 1; j <= M; ++j) { if (Board[i][j] == 'K') { BFS[i][j] = 1; BFSx[0] = i; BFSy[0] = j; czy = 1; break; } } if (czy) break; } int b = 0; int e = 1; int osady = 1; while (b < e) { int x = BFSx[b]; int y = BFSy[b]; if (x > 1 && Board[x - 1][y] != 'W' && BFS[x - 1][y] == 0) { BFSx[e] = x - 1; BFSy[e] = y; BFS[x - 1][y] = 1; if (Board[x - 1][y] == 'K') osady++; e++; } if (y > 1 && Board[x][y - 1] != 'W' && BFS[x][y - 1] == 0) { BFSx[e] = x; BFSy[e] = y - 1; BFS[x][y - 1] = 1; if (Board[x][y - 1] == 'K') osady++; e++; } if (x < N && Board[x + 1][y] != 'W' && BFS[x + 1][y] == 0) { BFSx[e] = x + 1; BFSy[e] = y; BFS[x + 1][y] = 1; if (Board[x + 1][y] == 'K') osady++; e++; } if (y < M && Board[x][y + 1] != 'W' && BFS[x][y + 1] == 0) { BFSx[e] = x; BFSy[e] = y + 1; BFS[x][y + 1] = 1; if (Board[x][y + 1] == 'K') osady++; e++; } b++; } if (osady == Osady) return 1; Board[r][c] = '.'; return 0; } void PrzeniesOsade(int r1, int c1, int r2, int c2) { Board[r2][c2] = 'K'; Board[r1][c1] = '.'; } /*int main () { return 0; }*/ |