UVA 679(p148)----Dropping Balls

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int k=1,d,n;
        scanf("%d%d",&d,&n);
        for(int i=1; i<d; i++)
        {
            if(n%2)
            {
                k*=2;
                n=(n+1)/2;
            }
            else
            {
                k=2*k+1;
                n/=2;
            }
        }
        printf("%d\n",k);
    }
    return 0;
}
题目地址:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=620

你可能感兴趣的:(UVA 679(p148)----Dropping Balls)