|
XI Olimpiad in Informatics 2003/2004
|
Task: zga
Guesswork
III stage competition, trial day |
|
Alternative formats: PostScript PDF
Byteazar has became a chronic gambler. He throws away all money in the casino playing
"guesswork". He purports it is possible to devise a game system that allows to beat the
casino.
A single game of guesswork consists in drawing consecutively 9 real numbers
belonging to (0;1) using uniform distribution. Upon drawing each number the player must
immediately guess the position of the number (with respect to greatness) among the 9 to
be chosen. Obviously, it is not possible to forsee the position - one has to take a guess.
If 9 positions have been correctly guessed, the player wins. Otherwise, the player loses.
If, for instance, we describe the first drawn number as the second biggest and then draw two
numbers smaller than it, we lose.
Task
Help Byteazar! Programme the best strategy for the guesswork you can. Write a programme
which will play multiple games of guesswork, winning as many as possible. The higher
the number of games won, the better evaluation of your programme will be. More precisely,
for each game won the casino pays 423,99 byte-dollars to the player, for each lost it collects
13,53 byte-dollars from the player. Your programme shall play 10^6 games. The number of points
you shall recieve will equal total profit divided by 10^4 and rounded to the closest
integer within [0,100].
You have to programme a module containing the following three procedures and functions:
- procedure inicjalizuj / void inicjalizuj()
(initialize in Polish)
- this procedure shall be called only once,
at the outset, before any game begins.
You can use it to initialize your data structures.
- procedure nowa_rozgrywka /
void nowa_rozgrywka () (new_game in Polish) - this procedure will be called
at the beginning of each game. You can use it to initialize the variables concerning
a single game.
- function kolejna_liczba (x : Double) : Integer /
int kolejna_liczba (double x) (next_number in Polish) - this
function recieves a drawn number x as a parameter, 0 < x < 1,
with a precision of 12 decimal positions. The function should calculate the position
of x among the 9 numbers drawn in this round and return the outcome. If the game is lost,
the function may return any integer within [1,9].
Files (Pascal)
In the zga_pas directory you shall find the following files:
- zga.pas - a frame of the game module containing empty procedures
inicjalizuj, nowa_rozgrywka and function kolejna_liczba.
You should write those procedures/functions.
- kasyno.pas - a programme generating many (as many as it is indicated in the
ILE_ZESTAWOW (number_of_games) constant) games of guesswork. Each game is played by means of the
procedures and functions of the zga.pas game module. You can use this programme to
test your game module.
- makefile - this files makes it possible to compile the kasyno.pas programme
with the game module zga.pas, using the make command.
Files (C/C++)
In the zga_c / zga_cpp directory you shall find the following files:
- zga.h - a file containing headers of the functions: inicjalizuj,
nowa_rozgrywka and kolejna_liczba.
- zga.c / zga.cpp - a frame of the game module containing empty
definitions of functions declared in the header file zga.h.
You should write those functions.
- kasyno.c / kasyno.cpp -a programme generating many (as many as it is
indicated in the ILE_ZESTAWOW (number_of_games) constant) games of guesswork.
Each game is played by means of the procedures and functions of the
zga.c / zga.cpp game module. You can use this programme to test your
game module.
- makefile - this files makes it possible to compile the
kasyno.c / kasyno.cpp programme with the game module
zga.c / zga.cpp, using the make command.
Solution
The result of your work should consist of a single file: zga.c or zga.cpp or
zga.pas.
Example
A hypothetical interaction between with programme could be as follows:
(the numbers returned by the function kolejna_liczba are in italics; 2 games
have been played):
Game 1
0.043319026120
1
0.933801434041
8
0.992050359372
9
0.145189967093
4
0.518803250649
6
0.093583048537
2
0.764309529654
7
0.338653748790
5
0.119437652934
3 Victory
Game 2
0.164020610610
2
0.205594263575
3
0.042637391231
1
0.147521628974
1 Defeat
0.946549875333
1
0.772946216573
1
0.152956276544
1
0.539653928563
1
0.552047936535
1
Print friendly version
|