fork(2) download
  1. #include <iostream>
  2. using namespace std;
  3. #include<bits/stdc++.h>
  4. //#define int long long
  5. //priority_queue <int> q; //maximum priority// top
  6. //priority_queue <int, vector<int>, greater<int>> a; //min priority
  7. //queue<int>q
  8. //stack<int>stack
  9. //unorderd_map<int,int>hash;
  10. //set<int>s; s.insert(4);for(auto it:v) cout<<it
  11. //if((s.find(x) != s.end())) >>>true x is present in set
  12. //sort(arr, arr + n, greater<int>());
  13. //---------------------------------------------------------------------------
  14. //vector<pair<int,int>>v; //v.push_back({2, map[i].second});
  15. //bool sortinrev(const pair<int,int> &a,
  16. // const pair<int,int> &b)
  17. //{
  18. // return (a.first > b.first);
  19. //}
  20.  
  21. // cout << pair[i].first << " "<< pair[i].second << endl; //auto it:v it.first
  22. // sort(v.begin(), v.end());
  23. //vector<vector<int> > vec( n , vector<int> (m));
  24. //cout<< *min_element(a.begin(), a.end()); //vector min
  25. //vector<int>arr(n,1);
  26. // if (binary_search(arr.begin(), arr.end(), 15)) `
  27. // int p=lower_bound(v.begin(),v.end(),make_pair(z,0))-v.begin();
  28. // myvector.back();
  29. //--------------------------------------------------------------------------------
  30. //dfs || bfs ||rec||dp||binarySearch
  31. //memset(arr,-1,sizeof(arr));
  32. // printf("%.2f\n", total);
  33. // cout << setprecision(6) << fixed <<dp[n-1] << endl; six digits after //decimal >>ex--4.675445
  34. //pow(2,3)>>>8
  35. //s.substr(1)// substring without first char;
  36. //s.substr(1,3) = "Geeks";eek Copy three characters of s1 (starting from position 1)
  37. // getline(cin, S);
  38. typedef long long ll;
  39. //O(N) – 10^8<<O(N^2) – 10^4>>O(logN) –  very big number
  40. // __gcd(m, n)
  41. // for (int i = 0; i <= n; i++) subset[i][0] = true; column zero (neche) vertical
  42.  
  43. #define mod 1000000007
  44.  
  45. int visited[10000][10000];
  46.  
  47. void dfs(vector<vector<char>>& board,int r ,int c ,int n )
  48. {
  49.  
  50. if(r>=n ||r<0 || c>=n ||c<0 || visited[r][c] )
  51. {
  52. return ;
  53.  
  54. }
  55. visited[r][c]=1;
  56. dfs( board, r+1 , c , n);
  57. dfs( board, r-1 , c , n);
  58. dfs( board, r , c+1 , n);
  59. dfs( board, r , c-1 , n);
  60.  
  61.  
  62.  
  63. if(board[r][c]=='o' && r!=n-1 && c!=n-1 && r!=0 && c!=0)
  64. {
  65. board[r][c]='x' ;
  66.  
  67. }
  68.  
  69.  
  70.  
  71. }
  72.  
  73. void solve(vector<vector<char>>& board)
  74. {
  75. int n = board.size();
  76. memset(visited,0,sizeof(visited));
  77.  
  78. dfs(board, 0 ,0 , n);
  79.  
  80.  
  81. }
  82.  
  83.  
  84.  
  85.  
  86.  
  87. int main() {
  88. ios_base::sync_with_stdio(false);
  89. cin.tie(NULL);
  90.  
  91. vector<vector<char>> vect
  92. {
  93. {'o', 'o', 'o','o'},
  94. {'o', 'o', 'o','o'},
  95. {'o', 'o', 'o','o'},
  96. {'o', 'o', 'o','o'},
  97.  
  98. };
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106. solve( vect);
  107.  
  108.  
  109.  
  110.  
  111. for (int i = 0; i < vect.size(); i++)
  112. {
  113. for (int j = 0; j < vect[i].size(); j++)
  114. {
  115. cout << vect[i][j] << " ";
  116. }
  117. cout << endl;
  118. }
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139. }
Success #stdin #stdout 0.13s 394292KB
stdin
Standard input is empty
stdout
o o o o 
o x x o 
o x x o 
o o o o