zoj 3293 找规律

其实我不知道要说什么,因为这道题的解法也是从别人那里看的,不想盗版,看看这位神牛的吧,讲得挺不错,就是要好生理解一下。

http://blog.csdn.net/xymscau/article/details/6688671

View Code
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstdlib>
 4 #include<cstring>
 5 typedef long long LL;
 6 int const N = 33;
 7 LL dp[N],pow2[N];
 8 void pre()
 9 {
10      dp[1]=2;
11      pow2[0]=1,pow2[1]=2;
12      for(int i=2;i<=32;i++)
13          dp[i]=(dp[i-1]<<1)+((1LL<<(i-1))-1)*(1LL<<(i-1))+(1LL<<i),pow2[i]=(pow2[i-1]<<1);
14 }
15 LL getsum1(LL n)
16 {
17    int l=0,r=32;
18    while(l<r)
19    {
20         int m=(l+r)>>1;
21         pow2[m]-1>n?(r=m):(l=m+1);
22    }
23    l--;
24    return (pow2[l]-1==n)?(dp[l]):(dp[l]+pow2[l]*(n-pow2[l]+1)+getsum1(n-pow2[l]+1));
25 }
26 int main()
27 {
28     LL l,r;
29     pre();
30     while(~scanf("%lld %lld",&l,&r))
31     {
32           printf("%lld\n",getsum1(r)-getsum1(l-1));
33     }
34     return 0;
35 }

转载于:https://www.cnblogs.com/nuoyan2010/archive/2013/05/09/3069115.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值