If player one is the first person to pick and it's a two-person game, then he will pick the coins 1, 3, 5, 7, 9, 11, etc. From the vague information you gave, just have the odd coins valued at 2 and the even coins valued at 1. That way, player one will always have more points than player two.
Although I'm pretty that's not what you meant, that's what it appears to other people. So either I'm right or you need to clear up your problem/challenge.
I think I got it..
Code int scoreP1, scoreP2, numCoins;
for (int i = 0; i < numCoins; i++) {
if (i % 2 == 0) {
scoreP1 += i;
} else {
scoreP2 += i;
}
}
As you can see, P1 will always have the higher score.
100 + 98 + 96...
P2: 99 + 97 + 95...
Still cant get the point. You say there is a row of coins with random to-the-players-unknown values. If so, how can there be a strategy to win?
As I understood this:
- A random row starting anywhere and ending anywhere
- The row got an even coin-count (lets say 4 to make it easy understanding MY problem with this)
- Each player picks a coin from one of the ends
From that point lets take two examples:
1| 4 - 6 - 5 - 3 (a range from 3-6)
2| 12 - 11 - 10 - 13 (10-13)
As the players dont know the values, instead of this only the range, they cant choose effectivly where to pick the next coin. So for the first game it would look like X - X - X - X to the players. How should they get any difference into that to build up a strategy?
We can just take an array with size even, Sort it in ascending order , then Player1 start picking coins from the End and Player2 starts picking from the beginning one by one.
IF that's what you meant by "Each player, in his turn, takes a coin from one of the ends of the row".
well here , Player 1 will win even if player2 decides to pick coins from the end.
Since player1 starts first , and picks the last coin which is the largest cause we sorted the array,
Then Player2 decides from whichever end he wants to pick up the coin,
Basically , player1 will always pick from the end , and even if player 2 does the same , Player1 will still win cause he started first and the largest number came to his pocket.
If all numbers are same in the array , then it'll always be a draw because the length of the array is even. Both players will end up with exactly same number of coins with same value.
well ,If a DE Linked list is filled with random values and both players can only pick up coins from the ends(and not from the middle),
The only strategy I can think of is,
Player 1 always compares the values of both ends and picks up the bigger one.
But this is not enough to ensure victory every time or make it a draw , what if the value at both ends are like [7,99,3,6] , Here , player 1 will pick 7 cause it's bigger than 6 , but then the row would look like [99,3,6] and in Player2's turn , of course he'll pick 99.This situation can occur multiple times in a larger row hence making Player2's sum larger.
I can't think of anything else.Are there supposed to be anymore rules ??
|