|
|||||||
|
Eggs
It is known, that if an egg is dropped from a sufficient height it breaks ugly. Formerly (the height of) the first floor was enough, but genetically muted hens lay eggs which don't break even after falling down from the height of the 100000000-th floor. Researches on toughness of eggs are proceeded in skyscrapers. A special scale of toughness of eggs has been developed: an egg has toughness of k floors if it doesn't break after falling down from the k-th floor but it breaks after falling down from the k+1-st one. If our skyscraper has n floors, we assume that every egg breaks after falling down from the n+1-st floor. We also assume that every egg dropped from the 0-th floor doesn't break. The manager of the laboratory resolved to cut down expences on research. He limited the number of eggs, which can be broken during a single experiment purposed to determine the toughness of eggs of a given kind. Moreover the number of egg drops has to be minimized. It means that given a fixed number of eggs of a given kind and a skyscraper one has to determine, in the minimum number of drops, what is the toughnes of eggs of this kind. TaskYour task is to write a module containing three procedures (functions in case of C/C++ language):
At the beginning of every experiment the program inspecting the run of the experiment will call the procedure nowy_eksperyment written by you and then it will repeat the following actions:
till the moment when your program has confirmed that it knows the toughness of eggs examined in the experiment (i.e. the procedure analizuj_odpowiedz puts the proper value into the global variable wiem). Note: Don't assume that a program inspecting the run of experiments actually fixes the toughness of eggs before starting the experiment. It can adjust it during the experiment, so that it suits to all previously given answers and makes your program ask maximum number of questions. Thus, you should try to minimize the number of questions, which your program would have to ask in the worst case. CommunicationThe communication between your module and the program inspecting the run of experiments is done through global variables. The number of floors of the skyscraper will be written in the global variable wysokosc of type Longint (in case of C/C++ language the type is long int). It will be a positive integer not greater than 100000000. The maximal number of eggs that can be broken during the experiment will be written in the global variable jajka of type Integer (in case of C/C++ language the type is int). It will be a positive integer not greater than 1000. Asking a question if an egg "survives" a fall from the k-th floor, is done in the procedure daj_pytanie by putting the number k into the global variable pietro of type Longint (in case of C/C++ language the type is long int). The answer to the question is put into the global variable odpowiedz of type Boolean (in case of C/C++ language the type is int). The confirmation to the question (i.e. the egg "survives") corresponds to the value TAK, and a negative answer (i.e. the egg breaks) corresponds to the value NIE, where TAK and NIE are constants valued respectively to true and false (in case of C/C++ language these are macros valued respectively to 1 and 0). When your program determines the toughness of the egg it should write in the procedure analizuj_odpowiedz a value TAK into the global variable wiem of type Boolean (in case of C/C++ language the type is int) and the toughness of the egg found by your program should be written into the global variable x of type Longint (in case of C/C++ language the type is long int). Directories and filesPeople programming in Pascal should prepare their solution in the directory JAJPAS, and the ones programming in C/C++ in the directory JAJC. In the directory JAJPAS (or JAJC) you'll find the following files:
OutputThe result of your work should be recorded on a floppy disk as the only file: JAJ.pas, JAJ.C or JAJ.cpp. |