Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save qiuwei/9483514 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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment