Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef pair<ll, ll> pl;
- typedef vector<ll> vl;
- typedef vector<pl> vpl;
- ///these are some Macros which you can use in your code too
- # define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
- # define MOD 1000000007
- # define endl '\n'
- # define INF 9e18
- # define PI 3.14159265358979323846
- # define lb lower_bound
- # define ub upper_bound
- # define mp make_pair
- # define pb push_back
- # define fi first
- # define se second
- # define all(a) a.begin(), a.end()
- # define iceil(n, x) (((n) + (x) - 1) / (x))
- //5.>map<int,int> m;
- // m[1]++;
- map<pair<ll, ll>, ll> m;
- void fun(ll x, ll y, bool ns, bool ew, ll n, vector<pair<ll, ll>>& ans)
- {
- if (n == 0)//base case
- {
- pair<ll, ll> temp; temp.first = x, temp.second = y;
- //distinct points to be added in the answer
- if (m[temp] >= 1)
- return;
- else
- {
- ans.push_back(temp);
- m[temp]++;//(x,y) is visited
- return;
- }
- }
- ////we need to make the choices
- if (ns)//chance to go in north south
- {
- fun(x, y + 1, false, true, n - 1, ans);//north
- fun(x, y - 1, false, true, n - 1, ans);//south
- }
- else//chance to in east west
- {
- fun(x + 1, y, true, false, n - 1, ans);//east
- fun(x - 1, y, true, false, n - 1, ans);//west
- }
- }
- int main()
- {
- fast;
- ll t = 1;
- // cin >> t;
- while (t--)
- {
- ll n; cin >> n;//number of steps
- //1.>vector<pair<ll,ll>>
- //pair<int,int> temp={1,2};
- //stl :
- // pair<int,int> p;
- // p.first=1,p.second=2;
- // 2.>vector<pair<ll,ll>> ans
- vector<pair<ll, ll>> ans;
- ///////recursive calls
- fun(0, 0, true, false, n, ans);
- fun(0, 0, false, true, n, ans);
- // //3.>stl sort function
- // // sort(a, a + n)
- // // (0,0) (-1,0) (-1,2);
- // //(-1,0) (-1,2) (0,0)
- // cout << ans.size() << endl;
- sort(ans.begin(), ans.end());
- // //4.>for(int i=0;i<n;i++)
- for (auto i : ans)//i will be treated as iterator of pair
- {
- //auto keyword** to remember
- cout << i.first << " " << i.second << " " << endl;
- }
- // vector<ll> v; v.pb(1); v.pb(2), v.pb(3);
- // // v->1 , 2, 3
- // for (int i = 0; i < v.size(); i++) cout << v[i] << " ";
- // cout << endl;
- // for (auto i : v)
- // {
- // cout << i << " ";
- // }
- //time complexity->O(2^n)//exponential
- //space complexity->O(n*n)
- }
- return 0;
- }
- /* stuff you should look for
- 1.>pair<int,int> p; (access as p.first and p.second)
- 2.>vector<pair<int,int>> ans; (vector of pairs)
- 3.>map<pair<int,int>,int> mp;
- 4.>sort(a.begin(),a.end())-> by default small will come first
- */
Add Comment
Please, Sign In to add comment