1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 #defineSC3 (x, Y, z) scanf ("%lld%lld%lld", &x, &y, &z)6 #definePF (x) printf ("%lld\n", X)7 #definefor (i,b,e) for (int i=b;i<=e;i++)8 #defineFOR1 (i,b,e) for (int i=b;i>=e;i--)9 #defineCL (x, y) memset (x,y,sizeof (×))Ten using namespacestd; OnetypedefLong Longll; All bit[ *]; - inta[ *]; - voidInit () the { -bit[0] =1; -for (I,1, to) - { +Bit[i] =2* bit[i-1]; - } + } A intMain () at { - ll N, L, U, MAX; - init (); - //cout << bit[0] << Endl; - while(~sc3 (N, L, U)) - { inMAX =0; -for (I,0, to) to { +A[i] = N%2; -N/=2; the } *FOR1 (I, to,0) $ {Panax NotoginsengMAX + =Bit[i]; - if((a[i] = =0&& MAX > U) | | (MAX > L && a[i] = =1))//the next condition is to consider the smallest max value that fits in the range theMAX-=Bit[i]; + } A PF (MAX); the } + return 0; -}View Code
The main consideration is the binary problem, there is a suitable range of the smallest ans value, is a good thinking problem
UVA 10718 Bit Mask