Skip to content

Instantly share code, notes, and snippets.

@qiuwei
Created March 11, 2014 11:08
Show Gist options
  • Select an option

  • Save qiuwei/9483725 to your computer and use it in GitHub Desktop.

Select an option

Save qiuwei/9483725 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#include <cassert>
using namespace std;
const int MAXD = 20;
vector<bool> tree(1<<20, true);
int main(){
int depth, num;
//while(cin>> depth>> num){
//for(int i = 0; i< (1<<depth); i++){
//tree[i] = false;
//}
//int cur = 1;
//int secondlast = 1<<(depth-1);
//for(int i = 0; i< num; i++ ){
//cur = 1;
//while(cur < secondlast){
//assert(cur < tree.size());
//if(tree[cur]){
//tree[cur] = false;
//cur = cur*2 + 1 ;
//}else{
//tree[cur] = true;
//cur = cur*2;
//}
//}
//}
//cout << cur << endl;
//}
while(cin >> depth >>num){
int k = 1;
for(int i = 1; i <depth; i++){
if(num%2 == 0){
k = k*2 + 1;
num = num/2;
}else{
k = k*2;
num = num/2 + 1;
}
}
cout << k << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment