Polish version    English version  
  History of OI -> VII OI 1999/2000 -> Problems


 News
 About Olympic
 History of OI
XVII OI 2009/2010
XVI OI 2008/2009
XV OI 2007/2008
XIV OI 2006/2007
XIII OI 2005/2006
XII OI 2004/2005
XI OI 2003/2004
X OI 2002/2003
IX OI 2001/2002
VIII OI 2000/2001
VII OI 1999/2000
Stage III - results
Stage II - results
Stage I - results
Problems
Regulations
Organization
Hints
Schedule
Stats
VI OI 1998/1999
V OI 1997/1998
IV OI 1996/1997
III OI 1995/1996
II OI 1994/1995
I OI 1993/1994
 OI books
 National team
 Olympic camps
 Photo gallery
 Links
 SIO
 MAIN
Niebieskie ksi.eczki
VII Olimpiada Informatyczna 1999/2000

Task: JAJ
Author: Marcin Mucha
Eggs

III stage contest  

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.

Task

Your task is to write a module containing three procedures (functions in case of C/C++ language):

  • nowy_eksperyment - this procedure will be called at the beginning of a new experiment (there can be more than one);
  • daj_pytanie - this procedure is used for asking a question: Does an egg break, if it is dropped from a given floor?; to ask the question one has to put the number of the floor (from which she/he is going to drop an egg) into a global variable pietro described below;
  • analizuj_odpowiedz - this procedure should read the value of the global variable odpowiedz, which contains the answer to the recent question (description of this variable is given below), and analyse the answer. If as a result of this analysis the toughness of a given kind of eggs is found, the procedure should indicate this fact by placing proper values into global variables x and wiem (details are given below).

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:

  • calling procedure daj_pytanie,
  • answering a question,
  • calling procedure analizuj_odpowiedz,

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.

Communication

The 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 files

People 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:

  • JAJmod.pas (or JAJmod.h and JAJmod.c) - a module containing definitions of constants TAK and NIE and declarations of global variables,
  • JAJ.pas - a frame of a module determinig toughness of eggs; you should supply this file with definitions of functions nowy_eksperyment, daj_pytanie and analizuj_odpowiedz (for C/C++ programmers headers of these functions are in the file JAJ.h, you have to write the file JAJ.C or JAJ.cpp with definitions of these functions),
  • test.pas (or test.c) - a sample program inspecting the run of experiments and using your module.

Output

The result of your work should be recorded on a floppy disk as the only file: JAJ.pas, JAJ.C or JAJ.cpp.




Print friendly version