XI Olimpiad in Informatics 2003/2004

Task: zga

Guesswork

III stage competition, trial day  
Source file: zga.*
Memory limit: 32 MB

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:

Files (Pascal)


In the zga_pas directory you shall find the following files:

Files (C/C++)


In the zga_c / zga_cpp directory you shall find the following files:

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