I was playing with the following problem and have a brute force approach but could not come up with a nice solution. The problem is as follows:
There are 2*N cards. You and your opponent split them up (N cards to you and N to them). You know exactly what cards they have and what order they will play them in.
The rules of the game are as follows: For the first N/2 rounds, the person with the highest card wins and for last N/2 rounds, the person with the lowest card wins.
Given these rules and the order your opponents plays there cards, what is the maximum amount of wins you can get.
Example:
You have the cards: 2, 5, 6, 7. Your opponent has the cards: 1, 8, 4, 3 and plays them in that order.
The maximum score you can get is 2 since you play a 7 to their 1, lose the 2nd and 3rd round, and then play 2 in the last round to win.
My ideas: split your cards into two piles, your larger numbered and lower numbered ones. Then figure out an optimum matching up.
Pseudocode/algorithmic ideas would be greatly appreciated.
EDITS: There are a total of N rounds. The first N/2 rounds: the higher card wins. The last N/2 rounds: the lower card wins. N must be even.
I suggest:
Similar for lower pile, inverting order.
First, create an array of N items (one per round). Each item is a list of "winning cards" for that round, i.e. the set of your cards which would win that round. In your example, you'd get {{2567},{},{2},{2}}
.
The following list gives some situations in which a card should be "assigned" to a round. This means that we decide that we'll play that card on that round and nothing can change that afterwards. After a card is assigned, the algorithm should go on after removing the assigned round from the set of rounds and the assigned card from the set of winning cards for any round.
It should be obvious that applying any of these rules in any situation would never reduce the number of possible wins, so applying them as much as possible before starting brute force is always a good idea.
Note that assigning a card to a round changes both the rounds and the cards that win in each round, so even if one of these rules is not applicable, it could become applicable after applying some other rule. So they must be tried iteratively until a full iteration on all of them produces no new assignments.
This is not a definitive solution but it surely will make things much easier for the final bruteforce step.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With