There is a 100-story building and you are given two eggs.
The eggs (and the building) have an interesting property
that if you throw the egg from a floor number less than X,
it will not break. And it will always brake if the floor
number is equal or greater than X. Assuming that you can
reuse the eggs which didn't broke; you got to find X in a
minimal number of throws. Give an algorithm to find X in
minimal number of throws.
Answer Posted / basvaraj s pinna
We should start from the second floor to identify the X
floor.
Step 1. Throw the one egg from second floor,
if it breaks in second floor then go to first floor,
through remaining one from the first floor
if it breaks on the first floor then X=1
else
X=2
If does not break in second floor, goto fourth floor and
throw the egg
if it breaks in fourth floor then go to third floor,
through the remaining egg from the third floor
if it breaks on the third floor then X=3
else
X=4
Similarly we should run floor = floor + 2, till one egg
breaks,
floor = floor + 2
if one egg breaks at floor then
Set currentfloor = floor -1 and check for remaining egg
throw from currentfloor, if egg breaks at currentfloor,
then X= currentfloor else X=floor
Else
floor = floor + 2
do until floor =100
| Is This Answer Correct ? | 10 Yes | 55 No |
Post New Answer View All Answers
What do you mean by dynamic memory allocation in c?
How is actual parameter different from the formal parameter?
How can I write a function that takes a format string and a variable number of arguments?
What is the difference between declaring a variable by constant keyword and #define ing that variable?
Why enum is used in c?
What is the use of c language in real life?
How can I make it pause before closing the program output window?
What are qualifiers and modifiers c?
please give me a VIRTUSA sample palcement papers.... you will only send TECHNICAL SECTION..... that is help for me Advance Thanks........................
i have to apply for rbi before that i need to know the the syllabus for the entrance questions. whethet it may be aps or techinical
Explain built-in function?
cin.ignore(80, _ _);This statement a) ignores all input b) ignores the first 80 characters in the input c) ignores all input till end-of-line d) iteration
largest Of three Number using without if condition?
Is there any possibility to create customized header file with c programming language?
exit () is used to a) exit () terminates the execution of the program itself b) exit () terminates the execution of the loop c) exit () terminates the execution of the block d) none of the above