[cpp] 描述:題意很簡單,可是如果要從L到U之間用 | 遍歷的話會超時,只能換種思路了 #include <cstdio> #include <cstdlib> int main() { // freopen("a.txt","r",stdin); int n,l,u; unsigned int m; while(scanf("%d%d%d",&n,&l,&u)!=EOF) { m=0; for(int i=31; i>=0; i--) if(m+ (1<<i) <=u&&( (n& (1<<i) ) ==0||( m<l&& (l& (1<<i) ) ) ) ) m+=(1<<i); printf("%u\n",m); } return 0; }