已知a<=x<=b , c<=y<=d, 求解x|y的最大值
挂科让人很伤心
整的我现在做什么都没有心情
#include <iostream>
using namespace std;
//已知a<=x<=b , c<=y<=d, 求解x|y的最大值
unsigned MaxOr(unsigned a, unsigned b, unsigned c, unsigned d )
{
unsigned m, tmp;
m = 0x80000000;
while ( m != 0 )
{
if ( b & d & m )
{
tmp = ( b - m ) | ( m - 1 );
if ( tmp >= a )
{
b = tmp;
break;
}
tmp = ( d - m ) | ( m - 1 );
if( tmp >= c )
{
d = tmp;
break;
}
}
m = m >> 1;
}
return b | d;
}
int main()
{
unsigned a, b, c, d;
cin>>a>>b>>d;
cout<<MaxOr(a, b, c, d)<<endl;
return 0;
}