Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int a[100][100], check[100][100],n,m;
- int loang(int x, int y)
- {
- int tkx[4] = {-1,0,1,0};
- int tky[4] = {0,1,0,-1};
- int queuex[100],queuey[100],u,v,u1,v1;
- queuex[1] = x;
- queuey[1] = y;
- int head = 1;
- int tail = 1;
- check[x][y] = 1;
- while (head <= tail)
- {
- u = queuex[head];
- v = queuey[head];
- head++;
- for (int k = 0; k <= 3; k++)
- {
- u1 = u + tkx[k];
- v1 = v + tky[k];
- cout << k << ' ' << u << ' ' << v << ' ' << u1 << ' ' << v1 << endl;
- if (u1>=1 && u1 <=m && v1>=1 && v1<=n && check[u1][v1]==0 && a[u1][v1]==1)
- {
- tail++;
- queuex[tail] = u1;
- queuey[tail] = v1;
- check[u1][v1] = 1;
- }
- }
- }
- return tail;
- }
- int main()
- {
- int i,j,max=0,tam;
- cin >> m >> n;
- for (i=1;i<=m;i++)
- for (j=1;j<=n;j++)
- cin >> a[i][j];
- for (i=1;i<=m;i++)
- for (j=1;j<=n;j++)
- check[i][j] = 0;
- for (i=1;i<=m;i++)
- {
- for (j=1;j<=n;j++)
- {
- if (a[i][j] == 1 && check[i][j] == 0)
- {
- tam = loang(i,j);
- if (tam > max) max = tam;
- }
- }
- }
- cout << max;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement