Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std ;
  3.  
  4. int n , m , yo[2005][2005] ;
  5. string s[2005] ;
  6. int lx , ly , hx, hy ;
  7.  
  8. void go( int x , int y )
  9. {
  10. if( x < 0 || x >= n ) return ;
  11. if( y < 0 || y >= m ) return ;
  12. if( s[x][y] == '*' )return ;
  13. if( yo[x][y] ) return ;
  14. yo[x][y] = 1 ;
  15. if( x < lx ) lx = x ;
  16. else if( x > hx ) hx = x ;
  17. if( y < ly ) ly = y ;
  18. else if( y > hy ) hy = y ;
  19.  
  20. go( x +1 , y ) ;
  21. go( x , y+1 ) ;
  22. go( x , y-1 ) ;
  23. go( x -1 , y ) ;
  24. }
  25.  
  26. int main()
  27. {
  28. cin >> n >> m ;
  29.  
  30. for( int i = 0 ; i < n ; i++ )
  31. {
  32. cin >> s[i] ;
  33. }
  34. for( int i = 0 ; i < n ; i++ )
  35. {
  36. for( int j = 0 ; j < m ; j++ )
  37. {
  38. if( !yo[i][j] && s[i][j] == '.' )
  39. {
  40. lx = i ;
  41. ly = j ;
  42. hx = i ;
  43. hy = j ;
  44. go( i , j ) ;
  45.  
  46. for( int r = lx ; r <= hx ; r++ )
  47. {
  48. for( int c = ly ; c <= hy ; c++ )
  49. {
  50. s[r][c] = '.' ;
  51. yo[r][c] = 1 ;
  52. }
  53. }
  54. }
  55. }
  56. }
  57.  
  58.  
  59. for( int i = 0 ; i < n ; i++ )
  60. {
  61. cout << s[i] <<endl;
  62. }
  63.  
  64. return 0 ;
  65.  
  66. }
  67.  
  68.  
  69. /*
  70.  
  71. ***..*......*...****.*****.*.....**.*******.******.*..***.***.**
  72. ***..*......*...****.*****.*.....**.*******.******.*..***.***.**
  73.  
  74. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement