I have two results and like to get the best "order" of both these. Example:
We have a race with 5 people in one race, and 7 in another. The outcome is: Race 1.
1. Karl
2. Fred
3. John
4. Peter
5. Sid
Race 2.
1. St开发者_如何学编程even
2. John
3. Karl
4. Peter
5. Aron
6. Fred
7. Kevin
The questin is: whats the top 7 of both these races?
Its quite obvious that that nr 1 is Karl in this case, since he hold one 1st place and one 3rd, which is better than Johns second and third place. However, Steven could be equally good but he did only participate in one race and should suffer some kind of penalty for that.
What are the known algorithms for this problem? Are there any trivial solutions? I just can't figure it out
You can relate the positions to weights (think of it as points)
For instance 1st position has a weight of 20. 2nd has 18. 3rd 16, etc.
Participation miss could relate to a weight of -5.
You can adjust the numbers as required.
To find the final result you add everyone's weights and compare the numbers.
I think it should work..
Another approach would be to create an ordering of the top nodes which are consistent with the ordering of the previous races. This could be done by using a max-flow algorithm.
A naive solution would be to have some kind of ID for all the players. Go through both lists and add any new IDs you come across to a separate list, called Positions for example. Set all values for these IDs to some large number that can not be a race position, call it BIG_VAL (eg. 100). Go through the first list and mark all the positions as the new values in the Positions list. This was just the first race, so there is nothing special here. Then go through the second list and add the second position results for those IDs into the Positions list. For the IDs that don't occur, add another BIG_VAL to their result. The list will now have the race positions in order, all that remains is to sort them. Karl will be 4, John will be 5, Fred will be 8, and so on in this list:
http://bit.ly/fvYtal
精彩评论