简体   繁体   中英

Dividing players into "winners" and "losers": how to prove that greedy solution gives optimal result?

I have a problem that states the following:

n players (where n is even) are to a play games against each other. Everyone will not necessarily play but a player can only play against someone else once. If two people do decide to play against each other, we have one loser and one winner. I then wish to partition my n players into two sets of size n/2: winners (W) and losers (L). I want all players in my winner set to have never lost against someone in my losers set.

This is impossible ex. for 4 players and games p1 won against p2, p2 won against p3, p3 won against p4 and p4 won against p1 then there is no way to partition the players into W and L. I do the next best thing, which is I wish to minimise my error: the number of pairs of players where a player in W has lost to a player in L (not playing against each other is not a loss).

I (think) I found a greedy solution to this problem. I simply sort the players by their number of losses and place the people with the least loses in my W set and fill in the rest to L. How do I go about proving that my greedy approach is in fact optimal? I have done several random tests and I can show that my approach will give a feasible solution but I don't know how to show that this does in fact minimise my error.

Your greedy algorithm is not optimal. It fails for:

 W      L
===    ===
 A  vs  x
 B  vs  y
 C  vs  z
 B  vs  A
 C  vs  A
 x  vs  y

The optimal partition is W=(A,B,C), L=(x,y,z), but you will put A in the loser set, because he has 2 losses.

You say you did some randomized tests. How did you validate that your greedy algorithm produced the correct results for these tests?

Consider the following outcomes:

Winner    Loser
Adam      John
Bob       John
John      Charles
John      David
John      Ernest
John      Frank
John      George

We tally up the losses and sort in ascending order:

Player    Losses
Adam      0
Bob       0
Charles   1
David     1
Ernest    1
Frank     1
George    1
John      2

Your algorithm divides the players as follows:

Winners    Losers
Adam       Ernest
Bob        Frank
Charles    George
David      John

The errors are (Charles, John) and (David, John); there are two errors. Consider instead the following division:

Winners    Losers
Adam       David
Bob        Ernest
Charles    Frank
John       George

There is no error in this division: there is no winner who lost to a loser. This is a better division, with less error; so your algorithm, as stated, is not optimal.

The fundamental problem with your algorithm is that it considers only the number of losses; prolific players can appear worse to this algorithm than they really are simply because they have more losses than others, despite possibly having many more wins.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM