k -> rope of desired length. l -> rope of given length m = 2; while(k % m) m *= 2; ans :: (log2(l) - log2(m) + 1). ex. k = 6,l = 8 so initially m = 2; after 1st iteration m = 4; then break; so min = log2(8) - log2(4) + 1 = 3 -2 + 1 = 2.
On Sat, Jul 2, 2011 at 1:16 AM, cegprakash <[email protected]> wrote: > nope > > On Jul 2, 1:14 pm, keyan karthi <[email protected]> wrote: > > yup :) > > > > On Sat, Jul 2, 2011 at 1:38 PM, Shalini Sah < > [email protected] > > > > > wrote: > > > i guess the no. of 1s in the binary representation of the number is the > > > answer..for 6 its 2... > > > > > On Sat, Jul 2, 2011 at 1:32 PM, cegprakash <[email protected]> > wrote: > > > > >> the length of the rope is l units. > > >> I can only cut any rope into two halves. > > > > >> for example if the length of the rope is 8 and we need a length of > > >> rope 6 > > > > >> we first cut into two halves and we get 4, 4 > > >> now we cut any of the half again and we get 4,2,2 > > > > >> now we can merge 4 and 2 and form a rope of length 6. > > > > >> in this example we need a minimum of 2 cuts to get the length of rope > > >> 6 from 8 > > > > >> assume that l is always a power of 2 and we need always a even length > > >> of rope from it how to find the number of minimum cuts needed to get > > >> the new rope?. > > > > >> -- > > >> You received this message because you are subscribed to the Google > Groups > > >> "Algorithm Geeks" group. > > >> To post to this group, send email to [email protected]. > > >> To unsubscribe from this group, send email to > > >> [email protected]. > > >> 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 [email protected]. > > > To unsubscribe from this group, send email to > > > [email protected]. > > > 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 [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- Varun Pahwa B.Tech (IT) 7th Sem. Indian Institute of Information Technology Allahabad. Ph : 09793899112 ,08011820777 Official Email :: [email protected] Another Email :: [email protected] People who fail to plan are those who plan to fail. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
