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
Differentiate between functions getch() and getche().
What are the application of void data type in c?
What are the types of assignment statements?
What are the types of variables in c?
Do you know what are the properties of union in c?
Explain how can I make sure that my program is the only one accessing a file?
Explain how many levels deep can include files be nested?
How can type-insensitive macros be created?
Explain about the functions strcat() and strcmp()?
Why is python slower than c?
Is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?
7-Given an index k, return the kth row of the Pascal's triangle. For example, when k = 3, the row is [1,3,3,1]. For reference look at the following standard pascal’s triangle.
What is the benefit of using const for declaring constants?
What are data structures in c and how to use them?
Where we use clrscr in c?