Polish version    English version  
  About Olympic -> Problems


 News
 About Olympic
About contest
Problems
I OI 1993/1994
II OI 1994/1995
III OI 1995/1996
IV OI 1996/1997
V OI 1997/1998
VI OI 1998/1999
VII OI 1999/2000
VIII OI 2000/2001
IX OI 2001/2002
X OI 2002/2003
XI OI 2003/2004
XII OI 2004/2005
XIII OI 2005/2006
XIV OI 2006/2007
XV OI 2007/2008
Problems archive
 History of OI
 OI books
 National team
 Olympic camps
 Photo gallery
 Links
 SIO
 MAIN
Niebieskie ksi.eczki
III Olympiad in Informatics 1995/1996

Task: MON
Author: Piotr Chrz±stowski-Wachtel
Five Coins

II stage contest  

We are given five coins A, B, C, D, E, of pairwise different weights. You have a pan scales which allows to compare the weights of two coins. Your task is to arrange these coins in an ascending weight order from the lightest to the heaviest. The scales is an expensive device. First seven pairs can be compared for free. The eighth one costs 1 zloty and each of the following comparisons is 125 times more expensive than the previous one. Decision, which coins should be compared in a certain moment, we can make depending on the results of the previous measurements. Find an algorithm, which sorts the coins so that the cost of scaling is the least.

Task

The solution may be written either in Pascal or in C.

 

Pascal

Here is the program that will allow you to run your solution. Fill in the body of the procedure sortujMonety from the file USORT.PAS. This procedure should sort the coins in an ascending weight order using the comparing function lzejsza and then output the found order with the procedure wynik. Procedure wynik will verify whether the found order of coins is indeed an ascending weight order.

The source code is written in the following files:
UMONETA.PAS - the definition of type Tmoneta,
UWAGA.PAS - the function lzejsza and the procedure wynik,
USORT.PAS -  the place for your solution,
MONETY.PAS - the main part of the program.

The procedure sortujMonety should use the type TMoneta defined in the file UMONETA.PAS:

unit UMoneta;
interface
   type
      TMoneta = (A, B, C, D, E);
   {It is not allowed to use the remaining declarations from this file}
implementation
   {...}
To compare coins and to output the result your program should use the function lzejsza and the procedure wynik declared in the file UWAGA.PAS:
unit UWaga;
interface
   uses UMoneta;
   function lzejsza(m1,m2:TMoneta):boolean;
   {It's value is true if the coin m1 is lighter than the coin m2,
    otherwise it's value is false.}
   procedure wynik(m1,m2,m3,m4,m5:TMoneta);
   {When you have enough information to arrange the coins,
    you should run the procedure wynik. The parameters m1, m2, m3, m4, m5 correspond with
    the coins ordered from the lightest to the heaviest.
    Remember, this procedure must be run only once.}
implementation
   {...}

You program should be written in the file USORT.PAS:

unit USort;
interface
   uses UMoneta,UWaga;
   procedure sortujMonety;
implementation
   {Bellow should be written the code of your solution.
    All the types, variables, functions, and procedures you declare should be local
    for this module.}
   procedure sortujMonety;
   begin
   end;
Among the functions, types and variables declared in the other files you are allowed to use only the function lzejsza, the procedure wynik, and the type Tmoneta. Only the module USORT.PAS may be changed. Only the file USORT.PAS will be judged, it will be compiled with another program verifying the correctness of your solution, thus the interface of the module must remain unchanged.

C

Here is the program that will allow you to run your solution. Fill in the body of the procedure sortujMonety from the file USORT.C. This procedure should sort the coins in an ascending weight order using the comparing function lzejsza and then output the found order with the procedure wynik. Procedure wynik will verify if the found order of coins is indeed an ascending weight order.

The source code of the program is written in the following files:

UMONETA.H, UMONETA.C - the definition of the type: TMoneta,
UWAGA.H, UWAGA.C - the function lzejsza and the procedure wynik,
USORT.H, USORT.C - the place for your solution,
MONETY.C - the main part of the program.

The procedure sortujMonety should use the type TMoneta defined in the file UMONETA.H:

typedef enum {A, B, C, D, E} TMoneta;

/* It is not allowed to use the remaining declarations in this file. */
To compare coins and to output the result your program should use the function lzejsza and the procedure wynik declared in the file UWAGA.H:
extern int lzejsza (TMoneta m1, TMoneta m2);
   /* It returns 1 (true) if the coin m1 is lighter than the coin m2,
      otherwise it returnes 0 (false). */

extern void wynik (TMoneta m1, TMoneta m2, TMoneta m3, TMoneta m4, TMoneta m5);
   /* When you have enough information to arrange the coins,
      you should run the procedure wynik. The Parameters m1, m2, m3, m4, m5 correspond with
      the coins ordered from the lightest to the heaviest.
      Remember, this procedure must be run only once. */

Among the functions, types and variables declared in the other files you are allowed to use only the function lzejsza, the procedure wynik, and the type Tmoneta. Only the module USORT.PAS may be changed. Only the file USORT.PAS will be marked, it will be compiled with another program verifying the correctness of your solution, thus the interface of the module must remain unchanged.




Print friendly version