Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- struct toaDo {
- int x, y;
- };
- int X[8] = {0,-1,0,1,-1,-1,1,1};
- int Y[8] = {-1,0,1,0,-1,1,1,-1};
- int main()
- {
- //freopen("input.txt", "r", stdin);
- int n, m;
- cin >> n >> m;
- int A[11][11];
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < m; j++)
- {
- cin >> A[i][j];
- }
- }
- toaDo QQ[100];
- int front = -1, rear = -1, res=0;
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < m; j++)
- {
- int count = 0;
- if (A[i][j] == 1)
- {
- struct toaDo D;
- D.x = i;
- D.y = j;
- rear = (rear + 1) % 100;
- QQ[rear] = D;
- count += 1;
- A[i][j] = 0;
- while (front != rear)
- {
- toaDo E;
- front = (front + 1) % 100;
- E.x = QQ[front].x;
- E.y = QQ[front].y;
- for (int direct = 0; direct < 8; direct++)
- {
- toaDo F;
- F.x = E.x + X[direct];
- F.y = E.y + Y[direct];
- if (F.x >= 0 && F.x < n && F.y >= 0 && F.y < m && A[F.x][F.y] == 1)
- {
- rear = (rear + 1) % 100;
- QQ[rear] = F;
- A[F.x][F.y] = 0;
- count += 1;
- }
- }
- }
- if (res < count) res = count;
- }
- }
- }
- cout << res;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement