NOJ [1328] TT Had a Cow

  • 问题描述
  • Smart TT across the maze safety, she met the big boss! Boss used his power again, then many pillars Drilled out from ground, that hurt TT's army seriously. TT was very angry, luckily, TT also owns some ability. the pillar's height was different, every time TT could choose one or some pillars to destroy, she can cut the same height, but she can't cut more than a pillar's height, that means, if the pillar is 1 2 3 4 5 6, TT could choose 4 5 6, each cut 2(become 2 3 4)or 4(become 0 1 2), but she can't cut 5, because 4 can't cut 5, 0 means this pillar was destroyed. Because her limited power, please calculate the minimun times to destroy all the pillars.
  • 输入
  • There are many cases. Each case with a integer N(1 <= N <= 2^32), means 1 to N pillars, the ith pillar's height is i.
  • 输出
  • for each case, output the minimun times to destroy all the pillars.


    规律题
    1——1     =1
    2——3     =2
    4——7     =3
    8——15   =4
    ............
    2^n——2^(n+1)-1 =n+1
    #include<stdio.h>
    #include<math.h>
    
    int main()
    {
      int n;
      while(~scanf("%d",&n))
      {
        int left=1,right=1;
        if(n==1)
          printf("1\n");
        else
        {
        while(1)
        {
          if(n<=right && n>=left)
          {
          	printf("%0.f\n",log(left)/log(2)+1);
            break;
          }
          else if(n>right)
          {
            left*=2;
            right=right*2+1;
          }
        }
        }
      }
      return 0;
    }
    




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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值