@Shady: I'd try something like this: For each n: Let m = the number of 1-bits in n. If k >= 1<<m, then output -1. For i = 1 to m do Replace the ith 1-bit of n (counting from the right) with the ith bit of k. Output the updated n.
Example: n = 27 = binary 11011, k = 5 = binary 00101: m = 4. Replace the first 1-bit of n with the first bit of k: n = 11011. Replace the 2nd 1-bit of n with the 2nd bit of k: n = 11001. Replace the 3rd 1-bit of n with the 3rd bit of k: n = 11001. Replace the 4th 1-bit of n with the 4th bit of k: n = 01001. Output 5. Dave On Feb 11, 12:30 am, shady <sinv...@gmail.com> wrote: > answer is always +ve, > > does anyone know how to code it ? > > > > On Sat, Feb 11, 2012 at 11:37 AM, Tushar <tushicom...@gmail.com> wrote: > > for the given test case in the problem, answer could have been zero > > > what does it mean by "without even reading zero" in the problm > > statement? > > > On Feb 9, 11:34 pm, shady <sinv...@gmail.com> wrote: > > > Hi All, > > > Anyway to implement this in a good mannerhttp:// > >www.spoj.pl/ARHN/problems/PRINCESS, solution is simple, > > > check for ones and then generate numbers is an increasing number... > > > so if a number n = 22(10110) > > > then for k = 1, ans = 2(10) > > > then for k = 2, ans = 4(100) > > > then for k = 3, ans = 6(110) > > > > Shady > > > -- > > You received this message because you are subscribed to the Google Groups > > "Algorithm Geeks" group. > > To post to this group, send email to algogeeks@googlegroups.com. > > To unsubscribe from this group, send email to > > algogeeks+unsubscr...@googlegroups.com. > > For more options, visit this group at > >http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.