Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int a[102][102];
- int main()
- {
- int n,m,i,j,s=0,cate=0,ani=1,ok=0;
- cin>>n>>m;
- for(i=1; i<=n; i++)
- {
- for(j=1; j<=m; j++)
- {
- cin>>a[i][j];
- s=s+a[i][j];
- }
- }
- do
- {
- ok=0;
- for(i=1; i<=n; i++)
- {
- for(j=1; j<=m; j++)
- {
- cate=0;
- if(a[i][j]==1)
- {
- if(a[i-1][j]==0)
- {
- cate++;
- }
- if(a[i+1][j]==0)
- {
- cate++;
- }
- if(a[i][j-1]==0)
- {
- cate++;
- }
- if(a[i][j+1]==0)
- {
- cate++;
- }
- if(cate>=2)
- {
- ok=1;
- a[i][j]=-1;
- s=s+a[i][j];
- }
- }
- }
- ani++;
- for(i=1;i<=n;i++)
- {
- for(j=1;j<=m;j++)
- {
- if(a[i][j]==-1)
- {
- a[i][j]=0;
- }
- }
- }
- }
- }
- while(s>0 && ok==1);
- if(s==0)
- {
- cout<<ani;
- }
- else
- {
- cout<<"-1";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement