奇妙的算法--UVA 679(二叉树的编号)

题干略

直接根据规律模拟最后一个小球的下落

#include <stdio.h>
#include <math.h>
#include <stack>
#include <iostream>
using namespace std;

int main(){
	int no_use,d,i;
	cin>>no_use;
	while(cin>>d>>i && d!=-1){
		int k=1;
		for(int l=0;l<d-1;l++){
			if(i%2){ k*=2;i=(i+1)/2;
			}
			else{ k=k*2+1;i/=2;
			}
			
		}
    
    cout<<k<<endl;
	}
	if(getchar()==-1) 
	return 0;
}

  

柳暗花明又一村
原文地址:https://www.cnblogs.com/ucandoit/p/8417933.html