Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. #include<cmath>
  6. #include<cctype>
  7. #include<vector>
  8. #include<queue>
  9. #include<map>
  10. #include<utility>
  11. using namespace std;
  12. char ar[100][100];
  13. void floodfill(int a,int b,int m)
  14. {
  15. int x,y;
  16. ar[a][b]='?';
  17. for(x=-1;x<4;x++){
  18. for(y=-1;y<4;y++){
  19. int newx=x+a,newy=y+b;
  20. if((newx>=0)&&(newx<m)&&(newy>=0)&&(newy<m)){
  21. if(ar[newx][newy]==1)floodfill(newx,newy,m);
  22. }
  23. }
  24. }
  25. }
  26. int main()
  27. {
  28. int i,j,k,l,m,n,count=0;
  29. while(scanf("%d",&m)==1){
  30. count=0;
  31. for(i=0;i<m;i++){
  32. cin>>ar[i];
  33. }
  34. for(k=0;k<m;k++){
  35. for(l=0;l<m;l++){
  36. if(ar[k][l]==1){
  37. floodfill(k,l,m);
  38. count++;
  39. }
  40. }
  41. }
  42. printf("%d\n",count);
  43. }return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement