You are playing a game with your friends up in a tall tower with N levels labelled 1 to N (1 <= N <= 100). You are given a object which is somewhat fragile, and you are warned that the object will break if you drop it from the "breaking level" or higher. That is, for the given object, there is a unique level H (1 <= H <= N) such that if the object is dropped from level H-1 or lower, it will not break, and if it is dropped from level H or higher, it will break. Your job is to determine the breaking level by dropping samples of the object from various levels of the building and observing the results.
Your friends have made the challenge a bit harder. You are given only two samples of the object. Once these have broken, there are no more objects to drop. There is one more restriction: you are given only a certain number, D, of opportunities to drop the object (D is much less than N). If you successfully determine the breaking level (the unique H defined above) before you run out of drop opportunities and using no more than the 2 samples of the object, you win the game and the unending respect and cash of your friends.
To simulate the dropping of the object from a level, your program will interact with a provided library named level. The library has four operations:
possible sequence of library calls:
uses level;For your information, here are the function and procedure declarations:
function GetN:integer ; function GetD:integer ; function Drop( level:integer ) : integer ; procedure Decide( level:integer ) ;
#include "level.h"in your source code. Create a project D.PRJ and add your file d.c (d.cpp) and the library level.obj to your project.
int GetN( void ) ; int GetD( void ) ; int Drop( int level ) ; void Decide( int level ) ;