uva12627

根据图形推公式

设g(k,i)为k小时后最下面i行红气球个数

#include<cstdio>
#define LL long long
#define maxn 1000
using namespace std;
LL c[maxn];
LL pow(LL x,LL n)
{
    LL res = 1;
    while(n > 0)
    {
        if(n&1)res=res*x;
        x=x*x;
        n>>=1;
    }
    return res;
}
LL g(LL k,LL i)
{
    if(i<=0||i>pow(2,k))return 0;
    if(k<=0)return 1;
    if(i>=pow(2,k-1))
        return 2*g(k-1,i-pow(2,k-1))+c[k-1];
    else return g(k-1,i);
}
int main()
{
    int n;
    LL k,a,b;
    scanf("%d",&n);
    c[0]=1;
    for(int i=1; i<=100; i++)
        c[i]=c[i-1]*3;
    for(int i=1; i<=n; i++)
    {
        scanf("%lld %lld %lld",&k,&a,&b);
        printf("Case %d: ",i);
        printf("%lld\n",g(k,pow(2,k)-a+1)-g(k,pow(2,k)-b));
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值