Advertisement
pratiyush7

Untitled

Oct 30th, 2021
952
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. vector<ll> findNthNumber(int N)
  2. {
  3.   vector<ll> arr(N + 1);
  4.   queue<long long> q;
  5.   for (int i = 1; i <= 9; i++)
  6.     q.push(i);
  7.   for (int i = 1; i <= N; i++) {
  8.     arr[i] = q.front();
  9.     q.pop();
  10.  
  11.     if (arr[i] % 10 != 0)
  12.       q.push(arr[i] * 10 + arr[i] % 10 - 1);
  13.     q.push(arr[i] * 10 + arr[i] % 10);
  14.     if (arr[i] % 10 != 9)
  15.       q.push(arr[i] * 10 + arr[i] % 10 + 1);
  16.   }
  17.   return arr;
  18. }
  19.  
  20. void mainSolve()
  21. {
  22.   ll n = 5;
  23.   ll a = 25;
  24.   vector<ll> v = findNthNumber(1000000);
  25.   ll pos = upper_bound(v.begin(), v.end(), a) - v.begin();
  26.   ll ans = pos + n - 1;
  27.   cout << v[ans] << endl;
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement