Falak_Ahmed_Shakib

RECRSION

May 29th, 2020 (edited)
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. typedef pair<ll,ll> pll;
  5. #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL))
  6. #define fi first
  7. #define se second
  8. #define pb push_back
  9. #define eb emplace_back
  10. ll const MOD=1000000007;
  11. const int M= 2e5 + 10;
  12. ll cost[M+10];
  13. bool vis[M+10];
  14. ll n,m,a,b;
  15. bool ok=false;
  16. vector<ll>v[M+1];
  17. ll tar;
  18. bool f=false;
  19. void call(ll s)
  20. {
  21. if(ok)return;
  22.  
  23. if(s==tar)
  24. {
  25. f=true;
  26. return;
  27. }else if(s>tar)
  28. {
  29. return ;
  30. }
  31.  
  32. call(s*10);
  33. call(s*20);
  34.  
  35.  
  36. }
  37.  
  38. int main()
  39. {
  40. fastread();
  41.  
  42.  
  43.  
  44. while(1)
  45. {
  46. f=false;
  47. cin>>tar;
  48. call(1);
  49.  
  50. if(f)cout<<"YES"<<endl;
  51. else cout<<"NO"<<endl;
  52. }
  53.  
  54. }
  55. // stack by RECURTION
  56. #include<bits/stdc++.h>
  57. using namespace std;
  58. typedef long long ll;
  59. typedef pair<ll,ll> pll;
  60. #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL))
  61. #define fi first
  62. #define se second
  63. #define pb push_back
  64. #define eb emplace_back
  65. ll const MOD=1000000007;
  66. const int M= 2e5 + 10;
  67. ll cost[M+10];
  68. bool vis[M+10];
  69. ll n,m,a,b;
  70. bool ok=false;
  71. vector<ll>v[M+1];
  72. ll tar;
  73. bool f=false;
  74.  
  75.  
  76. int main()
  77. {
  78. fastread();
  79.  
  80.  
  81.  
  82. while(1)
  83. {
  84. cin>>tar;
  85.  
  86. stack<ll>s;
  87.  
  88. s.push(1);
  89.  
  90. ll a;
  91.  
  92. bool f=false;
  93.  
  94. while(!s.empty())
  95. {
  96. a=s.top();
  97. s.pop();
  98. if(a==tar)
  99. {
  100. f=true;
  101. break;
  102. }else if(a>tar)s.pop();
  103.  
  104. if(a*10<=tar) s.push(a*10);
  105. if(a*20<=tar) s.push(a*20);
  106.  
  107.  
  108. }
  109.  
  110. if(f)cout<<"YES"<<endl;
  111. else cout<<"NO"<<endl;
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118. }
  119.  
  120. }
  121.  
  122.  
Add Comment
Please, Sign In to add comment