Another alternative soln.
int rec_cut(int l, int k) {
if (l == k) return 0;
int tmp = k - (l>>1);
return 1 + rec_cut(l>>1, tmp <= 0 ? k : tmp);
}
int main() {
int l, k;
scanf("%d%d", &l, &k);
printf("%d\n", rec_cut(l, k));
return 0;
}
Veni Vedi Slumber !
On Sat, Jul 2, 2011 at 9:47 PM, varun pahwa <[email protected]>wrote:
> @sunny thnx for the correction.
>
>
> On Sat, Jul 2, 2011 at 9:16 AM, varun pahwa <[email protected]>wrote:
>
>> @sunny ya i wanted to write the while(k % m == 0)
>>
>>
>> On Sat, Jul 2, 2011 at 3:47 AM, [email protected] <
>> [email protected]> wrote:
>>
>>> n&n-1 is the expression to find out if n is a power of 2...If n&n-1
>>> returns 0 its a power of 2 else its not.
>>> And what sunny said is also ryt....
>>>
>>>
>>> On Sat, Jul 2, 2011 at 3:47 PM, sunny agrawal
>>> <[email protected]>wrote:
>>>
>>>> @cegprakash
>>>> Expression resets the least significant set bit
>>>>
>>>>
>>>> On Sat, Jul 2, 2011 at 3:20 PM, mohit goel
>>>> <[email protected]>wrote:
>>>>
>>>>> May be this can work.....give any counter example...
>>>>> int count;
>>>>> main()
>>>>> {
>>>>> int l,rope,cuts;
>>>>> scanf("%d%d",&l,&rope);
>>>>> count =0;
>>>>>
>>>>> find_cuts(l,rope);
>>>>> printf("cuts needed is %d",count);
>>>>> getch();
>>>>> return 0;
>>>>> }
>>>>>
>>>>> int find_cuts(int l,int rope)
>>>>>
>>>>> {
>>>>>
>>>>> if(l==rope)
>>>>> return count;
>>>>> count++;
>>>>> printf("%d",count);
>>>>> l=l/2;
>>>>> if(l==rope)
>>>>> return count;
>>>>> if(rope>l)
>>>>> rope =rope-l;
>>>>>
>>>>> find_cuts(l,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.
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Sunny Aggrawal
>>>> B-Tech IV year,CSI
>>>> Indian Institute Of Technology,Roorkee
>>>>
>>>> --
>>>> 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.
>>
>>
>
>
> --
> 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.
>
--
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.