Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int a[100][100], check[100][100],n,m;
  5.  
  6. int loang(int x, int y)
  7. {
  8.     int tkx[4] = {-1,0,1,0};
  9.     int tky[4] = {0,1,0,-1};
  10.     int queuex[100],queuey[100],u,v,u1,v1;
  11.    
  12.     queuex[1] = x;
  13.     queuey[1] = y;
  14.     int head = 1;
  15.     int tail = 1;
  16.     check[x][y] = 1;
  17.    
  18.     while (head <= tail)
  19.     {
  20.         u = queuex[head];
  21.         v = queuey[head];
  22.         head++;
  23.        
  24.         for (int k = 0; k <= 3; k++)
  25.         {  
  26.             u1 = u + tkx[k];
  27.             v1 = v + tky[k];
  28.             cout << k << ' ' << u << ' ' << v << ' ' << u1 << ' ' << v1 << endl;
  29.             if (u1>=1 && u1 <=m && v1>=1 && v1<=n && check[u1][v1]==0 && a[u1][v1]==1)
  30.             {
  31.                 tail++;
  32.                 queuex[tail] = u1;
  33.                 queuey[tail] = v1;
  34.                 check[u1][v1] = 1;
  35.             }
  36.         }
  37.     }
  38.     return tail;
  39. }
  40.  
  41. int main()
  42. {  
  43.     int i,j,max=0,tam;
  44.    
  45.     cin >> m >> n;
  46.    
  47.     for (i=1;i<=m;i++)
  48.         for (j=1;j<=n;j++)
  49.             cin >> a[i][j];
  50.     for (i=1;i<=m;i++)
  51.         for (j=1;j<=n;j++)     
  52.             check[i][j] = 0;
  53.            
  54.     for (i=1;i<=m;i++)
  55.     {
  56.         for (j=1;j<=n;j++)
  57.         {
  58.             if (a[i][j] == 1 && check[i][j] == 0)
  59.             {
  60.                 tam = loang(i,j);
  61.                 if (tam > max) max = tam;
  62.             }
  63.         }
  64.     }
  65.        
  66.     cout << max;
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement