Advertisement
HashZayed

Manasa and stones

Sep 19th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. #include <cmath>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <set>
  7. using namespace std;
  8.  
  9. set<int> parentStones;
  10. set<int> lastStones;
  11. set<int>::iterator li;
  12.  
  13. int GetChild(int parent,int a, int b, int depth){
  14. int left=0,right=0;
  15.  
  16. li=parentStones.find(parent);
  17. if(li != parentStones.end()) return 0;
  18. depth-=1;
  19. parentStones.insert(parent);
  20. left=parent+a;
  21. right=parent+b;
  22. cout<<parent<<":"<<left<<":"<<right<<":"<<depth<<endl;
  23.  
  24. if(depth==1) {
  25. lastStones.insert(left);
  26. lastStones.insert(right);
  27. return 0;
  28. }else if(depth>1){
  29. GetChild(left,a,b,depth);
  30. GetChild(right,a,b,depth);
  31. return 0;
  32. }
  33. return 0;
  34. }
  35. int GetLastStones(int n,int a,int b){
  36. GetChild(0,a,b,n);
  37. return 0;
  38. }
  39. int PrintLastStones(){
  40. for(set<int>::iterator i=lastStones.begin();i!=lastStones.end();i++){
  41. cout<<*i<<" ";
  42. }
  43. return 0;
  44. }
  45.  
  46. int main() {
  47. /* Enter your code here. Read input from STDIN. Print output to STDOUT */
  48. int T,n,a,b;
  49. cin>>T;
  50. for(int i=0;i<T;i++){
  51. cin>>n>>a>>b;
  52. //cout<<n<<":"<<a<<":"<<b<<endl;
  53. GetLastStones(n,a,b);
  54. PrintLastStones();
  55. if(i<(T-1)) cout<<endl;
  56. lastStones.clear();
  57. parentStones.clear();
  58. }
  59. return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement