Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <cstdio>
- #include <vector>
- #include <iostream>
- #include <algorithm>
- #include <set>
- using namespace std;
- set<int> parentStones;
- set<int> lastStones;
- set<int>::iterator li;
- int GetChild(int parent,int a, int b, int depth){
- int left=0,right=0;
- li=parentStones.find(parent);
- if(li != parentStones.end()) return 0;
- depth-=1;
- parentStones.insert(parent);
- left=parent+a;
- right=parent+b;
- cout<<parent<<":"<<left<<":"<<right<<":"<<depth<<endl;
- if(depth==1) {
- lastStones.insert(left);
- lastStones.insert(right);
- return 0;
- }else if(depth>1){
- GetChild(left,a,b,depth);
- GetChild(right,a,b,depth);
- return 0;
- }
- return 0;
- }
- int GetLastStones(int n,int a,int b){
- GetChild(0,a,b,n);
- return 0;
- }
- int PrintLastStones(){
- for(set<int>::iterator i=lastStones.begin();i!=lastStones.end();i++){
- cout<<*i<<" ";
- }
- return 0;
- }
- int main() {
- /* Enter your code here. Read input from STDIN. Print output to STDOUT */
- int T,n,a,b;
- cin>>T;
- for(int i=0;i<T;i++){
- cin>>n>>a>>b;
- //cout<<n<<":"<<a<<":"<<b<<endl;
- GetLastStones(n,a,b);
- PrintLastStones();
- if(i<(T-1)) cout<<endl;
- lastStones.clear();
- parentStones.clear();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement