Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int a[101][101],nrel,b[101][101],c[101][101];
  5. void scrie(int x,int y,int d[101][101])///el)
  6. {
  7. if(d[x][y]==0)///==el
  8. {
  9. d[x][y]=1; ///-1
  10. nrel++;
  11. scrie(x+1,y,d);
  12. scrie(x,y+1,d);
  13. scrie(x-1,y,d);
  14. scrie(x,y-1,d);
  15. }
  16. }
  17. int main()
  18. {
  19. int n,m;
  20. cin>>n>>m;
  21. for(int i=1;i<=n;i++)
  22. {
  23. for(int j=1;j<=m;j++)
  24. {
  25. cin>>a[i][j];
  26. b[i][j]=a[i][j];
  27. }
  28. }
  29. for(int i=1;i<=n;i++)
  30. {
  31. a[i][0]=a[i][m+1]=1;
  32. }
  33. for(int j=1;j<=m;j++)
  34. {
  35. a[0][j]=a[n+1][j]=1;
  36. }
  37. for(int i=1;i<=n;i++)
  38. {
  39. c[i][0]=c[i][m+1]=1;
  40. }
  41. for(int j=1;j<=m;j++)
  42. {
  43. c[0][j]=c[n+1][j]=1;
  44. }
  45. int nr=0,nrmax=0;
  46. for(int i=1;i<=n;i++)
  47. {
  48. for(int j=1;j<=m;j++)
  49. {
  50. if(a[i][j]==0)///!-1 el=a[i][j]
  51. {
  52. nrel=0;
  53. scrie(i,j,a);///el
  54. nr++;
  55. if(nrel>nrmax)
  56. nrmax=nrel;
  57. }
  58. }
  59. }
  60. cout<<nr<<" "<<nrmax;
  61. nrmax=0;
  62. int lin,col;
  63. for(int i=1;i<=n;i++)
  64. {
  65. for(int j=1;j<=m;j++)
  66. {
  67. if(b[i][j]==1)
  68. {
  69. for(int p=1;p<=n;p++)
  70. {
  71. for(int q=1;q<=m;q++)
  72. {
  73. c[p][q]=b[p][q];
  74. }
  75. }
  76. nrel=0;
  77. c[i][j]=0;
  78. scrie(i,j,c);
  79. //cout<<nrel<<endl;
  80. if(nrel>nrmax)
  81. {
  82. nrmax=nrel;
  83. lin=i;
  84. col=j;
  85. }
  86. }
  87. }
  88. }
  89. cout<<nrmax<<" "<<lin<<" "<<col;
  90. /*for(int i=1;i<=n;i++)
  91. {
  92. for(int j=1;j<=m;j++)
  93. {
  94. cout<<a[i][j]<<" ";
  95. }
  96. cout<<endl;
  97. }*/
  98. return 0;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement