uva 679 Dropping Balls

/* *********************************************** Author :xryz Email :[email protected] Created Time :4-14 21:16:41 File Name :DroppingBalls.cpp ************************************************ */

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;

int main()
{
    int n,i,k,t,m;
    scanf("%d",&t);
    while(~scanf("%d",&n))
    {
        if(n==-1) break;
        scanf("%d",&m);
        k=1;
        for(i=0;i<n-1;i++)
        {
            if(m%2) {k=2*k;m=(m+1)/2;}
            else {k=2*k+1;m=m/2;}
        }
        printf("%d\n",k);
    }
    return 0;
}

你可能感兴趣的:(uva 679 Dropping Balls)