Distribute prizes for the tournament system

I am looking for a way to distribute a number across x units. I don’t even know how to do this, so I’ll give an example:

There is a tournament in which the total prize is $ 1,000. I want the top 20 winners / applicants to win any of this.
I need a mathematical algorithm / formula that will distribute it among these players and which gives me the right to control some other distribution factors.

For example, the factor: I want the first-level winner to get $ 300. The main winner No. 2 will receive a smaller percentage of this. The general distribution should give everyone something, while the main winner is No. 20 (the last), who will receive at least X $.
X $ is another factor I want to control.

Any idea? Does this problem have a name (and what name is it)? Any code sample?

Edit # 1 is my first sentence :

#include <conio.h>
#include <vector>

#define TOTAL                       100
#define WINNERS                     15
#define FIRST_WINNER_PERCENTAGE     0.30

void distribute_1(::std::vector<double> * const prizes)
{
    prizes->clear();

    double total = TOTAL;
    double winning_percentage = FIRST_WINNER_PERCENTAGE;
    double slope = 0.5;
    int winners = WINNERS;

    double winning = 0;
    for(int i = 0; i < winners; i++, total -= winning, winning_percentage /= 2)
    {
        winning = total * winning_percentage;
        prizes->push_back(winning);
    }
}
void distribute_2(::std::vector<double> * const prizes)
{
    prizes->clear();

    double total = TOTAL;
    double winning_percentage = FIRST_WINNER_PERCENTAGE;
    double slope = 0.5;
    int winners = WINNERS;

    double winning = 0;
    for(int i = 0; i < winners; i++, total -= winning/*, winning_percentage /= 2*/)
    {
        winning = total * winning_percentage;
        prizes->push_back(winning);
    }
}
void distribute_3(::std::vector<double> * const prizes)
{
    prizes->clear();

    double total = TOTAL;
    double winning_percentage = FIRST_WINNER_PERCENTAGE;
    double slope = 0.0005;
    int winners = WINNERS;

    double winning = 0;
    for(int i = 0; i < winners; i++, total -= winning, winning_percentage -= slope)
    {
        winning = total * winning_percentage;
        prizes->push_back(winning);
    }
}
void distribute_4(::std::vector<double> * const prizes)
{
    prizes->clear();

    double total = TOTAL;
    double winning_percentage = FIRST_WINNER_PERCENTAGE;
    double slope = 1 / WINNERS;
    int winners = WINNERS;

    double winning = 0;
    for(int i = 0; i < winners; i++, total -= winning, winning_percentage -= slope)
    {
        winning = total * winning_percentage;
        prizes->push_back(winning);
    }
}

void main()
{
    ::std::vector<double> prizes;

    distribute_1(&prizes);
    distribute_2(&prizes);
    distribute_3(&prizes);
    distribute_4(&prizes);

    double total_granted = 0;
    for(int i = 0; i < WINNERS; i++)
    {
        total_granted += prizes[i];
        printf("%lf\n", prizes[i]);
    }
    printf("-\n%lf\n", total_granted);

    _getch();
}

This is how far I could reach. The problem with this, for example, is if, if you set, for example, "WINNERS" to 5, the algorithm does not reach the sum of "TOTAL" (100 in this example) or even closer (I get a total of 83).

Cristy Solution :

#include <conio.h>
#include<iostream>
//using arithmetic progression
using namespace std;
int i;
float ratio;
float first_prize;
float s;
int main()
{
    float money=1000;
    const int total_prizes =        10;
    float last_prize =              99;
    float prizes[total_prizes+1];

    /**/first_prize=2*money/total_prizes-last_prize; //last member of the progresion
    ratio=(first_prize-last_prize)/(total_prizes-1);
    prizes[total_prizes]=last_prize;
    for(i=total_prizes-1;i>=1;i--){
       prizes[i]=prizes[i+1]+ratio;
       money-=prizes[i];
    }
    for(i=1;i<=total_prizes;i++){
        printf("%d) %.2f\n",i,prizes[i]);
        s+=prizes[i];
    }
    printf("TOTAL SUM:%.2f\n",s);
    printf("Ratio: %.2f", ratio);
    _getch();
}
+3
source share
5 answers

Here is 1:15 here, and I solve the math :)).
Using arithmetic progression.
I used everything to determine so you can easily change them.

#include<iostream>
//using arithmetic progression
using namespace std;
FILE *g=fopen("output.out","w");
#define last_prize 10
#define total_prizes 20
int i;
float prizes[total_prizes+1];
float money=1000;
float ratio;
float first_prize;
float s;
//a1=last_prize
//an=first_prize
int main(){
 first_prize=2*money/total_prizes+last_prize; //last member of the progresion
 ratio=(first_prize-last_prize)/(total_prizes-1);
 prizes[total_prizes]=last_prize;
    for(i=total_prizes-1;i>=1;i--)
       prizes[i]=prizes[i+1]+ratio;
 for(i=1;i<=total_prizes;i++){
  fprintf(g,"%d) %.2f\n",i,prizes[i]);
  s+=prizes[i];
 }
 fprintf(g,"TOTAL SUM:%.2f",s);
return 0;
}

CONCLUSION:

1) 90.00
2) 85.79
3) 81.58
4) 77.37
5) 73.16
6) 68.95
7) 64.74
8) 60.53
9) 56.32
10) 52.11
11) 47.89
12) 43.68
13) 39.47
14) 35.26
15) 31.05
16) 26.84
17) 22.63
18) 18.42
19) 14.21
20) 10.00
TOTAL SUM:1000.00

As you can see, they add up to exactly $ 1,000.00: D

:
INPUT:

#define last_prize 30
#define total_prizes 5

:

1) 370.00
2) 285.00
3) 200.00
4) 115.00
5) 30.00
TOTAL SUM:1000.00
+3

.

#include<iostream>
using namespace std;
FILE *g=fopen("output.out","w");
int i;
int prizes[21];
int money=1000;
int main(){
    for(i=1;i<=20;i++){
       prizes[i]=(float)(15+(20-i))/100*money;
       money-=prizes[i];
    fprintf(g,"%d) %d\n",i,prizes[i]);
      }
return 0;
}

:

1) 340
2) 217
3) 141
4) 93
5) 62
6) 42
7) 29
8) 20
9) 14
10) 10
11) 7
12) 5
13) 4
14) 3
15) 2
16) 2
17) 1
18) 1
19) 1
20) 0

, :). .

:
1- : 30% (1000 $) = ~ 330 $
2- : 30% (670 $) = ~ 201
3- : 30% ... ..

(15+ (20-i)) 20, , :
, .

1) 200
2) 160
3) 128
4) 102
5) 82
6) 65
7) 52
8) 42
9) 33
10) 27
11) 21
12) 17
13) 14
14) 11
15) 9
16) 7
17) 6
18) 4
19) 4
20) 3

EDIT: . ( x% ). ...

+2

- , 3 (70%/20%/10%), , . , , , , .

P (i) = N (i) =

1) ( i) P (i) * N (i) = 1000 $

2) P (1)/P (2) = 70/20

3) P (2)/P (3) = 20/10

3 3 - .

P (1) = 300 $. .

. , PGA , -, .

+1

, M, n , k , - k , , . , ,

x + k * x + k ^ 2 * x... k ^ (n-1) * x = M x (k ^ n-1)/(k-1) = M

x , k, : -)

0

The formula in Christie's first line is wrong. first_prize = 2 * money / total _prizes + last_prize; This should be first_prize = 2 * money / total_prizes - last_prize;

Here is my solution in python, this will add a residual to the winners.

starting_amount = (((winnings * 2) / float(no_of_winners)) - last_amount)

difference = (last_amount - starting_amount) / float(no_of_winners - 1)
for rank in range(1, no_of_winners + 1):
    reward = starting_amount + difference * (rank - 1) 
    reward = round_amount(reward)
    winnings -= reward
    winning_amount[rank] = reward

residual_winnings = winnings
residual_shares = {1: 0.5, 2: 0.3, 3: 0.2} 

if no_of_winners < 3: 
    winning_amount[1] += residual_winnings
else:
    for rank in residual_shares:
        reward = residual_winnings * residual_shares[rank]
        reward = round_amount(reward)
        winning_amount[rank] += reward
0
source

Source: https://habr.com/ru/post/1758076/


All Articles