Advertisement
Guest User

foto

a guest
Oct 26th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int Width, Height, lim;
  5. bool mat[100][100];
  6. int maxi = -1;
  7.  
  8. void Process(int Y, int X) {
  9. mat[Y][X] = 1;
  10. if (X + 1 <= Width - 1)
  11. if (mat[Y][X + 1] == 0) {
  12. lim++;
  13. Process(Y, X + 1);
  14. }
  15.  
  16. if (X - 1 >= 0)
  17. if (mat[Y][X - 1] == 0) {
  18. lim++;
  19. Process(Y, X - 1);
  20. }
  21.  
  22. if (Y - 1 >= 0)
  23. if (mat[Y - 1][X] == 0) {
  24. lim++;
  25. Process(Y - 1, X);
  26. }
  27.  
  28. if (Y + 1 <= Height - 1)
  29. if (mat[Y + 1][X] == 0) {
  30. lim++;
  31. Process(Y + 1, X);
  32. }
  33. }
  34.  
  35. int main() {
  36. cin >> Width >> Height;
  37. for (int i = 0; i <= Height - 1; i++)
  38. for (int k = 0; k <= Width - 1; k++)
  39. cin >> mat[i][k];
  40.  
  41. for (int i = 0; i <= Height - 1; i++)
  42. for (int k = 0; k <= Width - 1; k++) {
  43. if (mat[i][k] == 0) {
  44. lim = 1;
  45. Process(i, k);
  46. if (lim > maxi)
  47. maxi = lim;
  48. }
  49. }
  50.  
  51. cout << maxi;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement