Thursday, June 02, 2011

Re: [Cpp-Programming] i'm facing


I think to have the highest possibility of selection you would want to stay in the queue as long as possible. One of the way I think is ,

If you know the number of men , find the maximum power of 2 which is less than n and choose that position for you. That ways you will always be in even position until the end.

For example , suppose you have 50 men to start with, choose 32 as your position
50 men, position 32
==> 25 men, position 16
==> 12 men, position 8
==> 6 men, position 4
==> 3 men, position 2
==> 1 men , position 1 ==> selected :)

Saurabh

On Fri, Jun 3, 2011 at 12:20 AM, DEEPAK KUSHWAH <deepakkushwah2302@gmail.com> wrote:
hi praveen,
that is to be given by the user

On 6/2/11, Praveen Nuthulapati <praveen2k4@gmail.com> wrote:
> Hi Deepak,
> how many crew is the captain selecting ?
>
> do you get a array out of bounds error?
>
> Praveen
>
> On Thu, Jun 2, 2011 at 10:18 AM, Deepak <deepakkushwah2302@gmail.com> wrote:
>> below is a code chef problem:
>> The captain of the ship TITANIC is a little .... off the track. He
>> needs to select the crew for the ship. But everyone seems to be
>> eligible. So to test their intelligence, he plays a game.
>> The contestants have to stand in a line. They are given the numbers in
>> the order in which they stand, starting from 1. The captain then
>> removes all the contestants that are standing at an odd position.
>> Initially, standing people have numbers - 1,2,3,4,5...
>> After first pass, people left are - 2,4,...
>> After second pass - 4,....
>> And so on.
>> You want to board the ship as a crew member. Given the total number of
>> applicants for a position, find the best place to stand in the line so
>> that you are selected.
>>
>>
>> i've done it by taking an array and eliminating the nos recursively
>> but it is saying time limit exceeded
>> can u please tell me the optimized algorithm for such problem
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "C++ Programming" group.
>> To post to this group, send email to cpp-programming@googlegroups.com.
>> To unsubscribe from this group, send email to
>> cpp-programming+unsubscribe@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/cpp-programming?hl=en.
>>
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "C++ Programming" group.
> To post to this group, send email to cpp-programming@googlegroups.com.
> To unsubscribe from this group, send email to
> cpp-programming+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/cpp-programming?hl=en.
>
>

--
You received this message because you are subscribed to the Google Groups "C++ Programming" group.
To post to this group, send email to cpp-programming@googlegroups.com.
To unsubscribe from this group, send email to cpp-programming+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cpp-programming?hl=en.


--
You received this message because you are subscribed to the Google Groups "C++ Programming" group.
To post to this group, send email to cpp-programming@googlegroups.com.
To unsubscribe from this group, send email to cpp-programming+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cpp-programming?hl=en.

0 Comments:

Post a Comment

<< Home