ZJNU 1699 - Bits

Available priority should find the maximum of 2 ^ n-1 the number of

L If the number of digits is not equal to the number of bits r, then the number 2 ^ n-1 is the optimal solution (each full 1)

If the number of l and r are the same, look at whether the r 2 ^ n-1, in line with the direct return, if demolition does not meet the highest level continue to look for

Example, l = 10 r = 14

I.e. 1010 ~ 1110 B

L and the same number of bits r 1 and r is incomplete

The highest level can be removed after 1

Looking median maximum minimum number of 10 ~ 110B

Different digits, return directly to 11B

Then the final answer is 1000B + 11B = 8 + 3 = 11

. 1 #include <stdio.h>
 2 typedef Long  Long LL;
 . 3  LL FD (A LL, LL B)
 . 4  {
 . 5      LL I;
 . 6      for (I = . 1 ; I <= B + . 1 ; I * = 2 );
 . 7      i / = 2 ; // find the maximum power of less than or equal to 2, i 
. 8      IF (a < i)
 . 9          return I- . 1 ;
 10      the else 
. 11          return FD (AI, BI) + i; // split the highest 1 bit, and then find the maximum value in line with the meaning of the questions on the rest of the lower 
12  }
 13  int main(){
14     int T,t;
15     ll a,b;
16     scanf("%d",&T);
17     for(t=0;t<T;t++)
18     {
19         scanf("%lld%lld",&a,&b);
20         printf("%lld\n",fd(a,b));
21     }
22     
23     return 0;
24 }

 

Guess you like

Origin www.cnblogs.com/stelayuri/p/12236276.html