Advertisement
Negru_Diana

eroziune.pb

Feb 24th, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. int a[102][102];
  4. int main()
  5. {
  6. int n,m,i,j,s=0,cate=0,ani=1,ok=0;
  7. cin>>n>>m;
  8. for(i=1; i<=n; i++)
  9. {
  10. for(j=1; j<=m; j++)
  11. {
  12. cin>>a[i][j];
  13. s=s+a[i][j];
  14. }
  15. }
  16. do
  17. {
  18. ok=0;
  19. for(i=1; i<=n; i++)
  20. {
  21. for(j=1; j<=m; j++)
  22. {
  23. cate=0;
  24. if(a[i][j]==1)
  25. {
  26. if(a[i-1][j]==0)
  27. {
  28. cate++;
  29. }
  30. if(a[i+1][j]==0)
  31. {
  32. cate++;
  33. }
  34. if(a[i][j-1]==0)
  35. {
  36. cate++;
  37. }
  38. if(a[i][j+1]==0)
  39. {
  40. cate++;
  41. }
  42. if(cate>=2)
  43. {
  44. ok=1;
  45. a[i][j]=-1;
  46. s=s+a[i][j];
  47. }
  48. }
  49. }
  50. ani++;
  51. for(i=1;i<=n;i++)
  52. {
  53. for(j=1;j<=m;j++)
  54. {
  55. if(a[i][j]==-1)
  56. {
  57. a[i][j]=0;
  58. }
  59. }
  60. }
  61. }
  62. }
  63. while(s>0 && ok==1);
  64. if(s==0)
  65. {
  66. cout<<ani;
  67. }
  68. else
  69. {
  70. cout<<"-1";
  71. }
  72. return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement