Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- #include<algorithm>
- #include<cmath>
- #include<cctype>
- #include<vector>
- #include<queue>
- #include<map>
- #include<utility>
- using namespace std;
- char ar[100][100];
- void floodfill(int a,int b,int m)
- {
- int x,y;
- ar[a][b]='?';
- for(x=-1;x<4;x++){
- for(y=-1;y<4;y++){
- int newx=x+a,newy=y+b;
- if((newx>=0)&&(newx<m)&&(newy>=0)&&(newy<m)){
- if(ar[newx][newy]==1)floodfill(newx,newy,m);
- }
- }
- }
- }
- int main()
- {
- int i,j,k,l,m,n,count=0;
- while(scanf("%d",&m)==1){
- count=0;
- for(i=0;i<m;i++){
- cin>>ar[i];
- }
- for(k=0;k<m;k++){
- for(l=0;l<m;l++){
- if(ar[k][l]==1){
- floodfill(k,l,m);
- count++;
- }
- }
- }
- printf("%d\n",count);
- }return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement