2345515 3444441325 3444441325
Moderator: Board moderators
if(U[i]==0&&N[i]==0)
else if(U[i]==1&&N[i]==1)
U[i]==1&&N[i]==0
U[i]==0&&N[i]==1
9
4
17
435
905
625
409
712
14721
23460
29462
19554
17216
382924
237589
257219
234343
499600
14223127
16692359
13133233
19429997
10902496
957429345
1305069817
1880088222
704659827
1542920241
given a 32-bit unsigned integer
127 50 605150unsigned int L,U,N;
unsigned int get_M();
int main()
{
while(1)
{
cin>>N>>L>>U;
if(cin.eof()) break;
cout<<get_M()<<endl;
}
return 0;
}
unsigned int get_M()
{
unsigned int M,t;
int i;
for(M=L,i=31;i>=0;i--)
{
if(!(N&(1<<i))) //if the ith bit is OFF
{
t=M|(1<<i); //turn ON the ith bit of M
if(t<=U)
M=t;
}
}
return M;
}predator wrote:hi i am getting WA in this problem. now i checked my code with the sample given in the other post .. they don't match but i dont know whats wrong with my code or algo. can anyone check it plz?

2709727097 1717317173 3015630156
1142911429 2225322253 3015630156
3083430834 3060830608 3230932309
2832328323 1288712887 3230932309
1390913909 1367713677 3230932309
2150721507 53335333 3230932309
21072107 2429024290 3230932309
3274332743 2447124471 3230932309
2660126601 1153311533 32655326552122111110
3013643834
3224802381
1462638972
2904053386
2144245788
3230930708
3168118200
1634840694
AC
Algorithm is correct it was because of a simple mistake in implementation that I'd got WA. Users browsing this forum: No registered users and 0 guests