Want to try solving this problem? You can submit your code online if you log in or register.
C Rock. Paper. Scissors. The rules are simple. The game is contested by two people over N rounds. During each round, you and your opponent simultaneously throw either Rock, Paper or Scissors. Rock beats Scissors, Scissors beats Paper, and Paper beats Rock. If your throw beats your opponent’s, you gain one point. Conversely, if their throw beats yours, you lose one point.
Your opponent is very predictable. You know that they will throw Rock in the first R_{a} rounds, throw Paper in the next P_{a} rounds, then finally throw Scissors in the last S_{a} rounds, where R_{a} + P_{a} + S_{a} = N.
You will throw Rock in R_{b} rounds, Paper in P_{b} rounds, and Scissors in S_{b} rounds, where R_{b} + P_{b} + S_{b} = N. However, as you are an experienced player, you may throw these in any order you like.
At the beginning of the game, you start with 0 points. What is the maximum number of points you can finish with?
Your program should output a single integer: the maximum number of points you could score after all N rounds have been played. Note that this number may be positive, negative, or zero.
5 2 2 1 1 3 1
4
4 1 2 1 4 0 0
-1
1 0 0 1 0 0 1
0
In the first sample input, there are N = 5 rounds, where your opponent will throw Rock twice, then Paper twice, then Scissors once. You must throw Rock once, Paper three times and Scissors once. Here is one way you can order your throws:
Round | Your Throw | Their Throw | Your Result | Points |
---|---|---|---|---|
1 | Paper | Rock | Win! | +1 |
2 | Paper | Rock | Win! | +1 |
3 | Scissors | Paper | Win! | +1 |
4 | Paper | Paper | Draw | 0 |
5 | Rock | Scissors | Win! | +1 |
This results in a total of 4 points, which is the maximum possible.
In the second sample input, there are N = 4 rounds, where your opponent will throw Rock once, then Paper twice, then Scissors once. You must throw Rock four times, and cannot throw Paper or Scissors. There is only one way you can order your throws:
Round | Your Throw | Their Throw | Your Result | Points |
---|---|---|---|---|
1 | Rock | Rock | Draw | 0 |
2 | Rock | Paper | Lose... | -1 |
4 | Rock | Paper | Lose... | -1 |
4 | Rock | Scissors | Win! | +1 |
This results in a total of -1 points, which is the maximum possible. Note that the answer can be negative!
In the third sample input, there is N = 1 round. Your opponent will throw Scissors in this one round, and you will also throw Scissors. This results in a draw, so you will score 0 points.
For all test cases:
Furthermore:
For Subtask 1 (10 marks), N = 1. Sample Input 3 is an example of a case that could be in this subtask.
Hint: There is only one round, so all you need to do is check whether your throw wins, loses, or draws against your opponent, and output 1, -1 or 0 respectively.
For Subtask 2 (25 marks), you only throw Rock. More formally, R_{b} = N, P_{b} = 0, and S_{b} = 0. Sample Input 2 is an example of a case that could be in this subtask.
Hint: Since you’re only throwing Rock each time, you just need to check which of your opponent’s throws wins, loses or draws against Rock, and count the results appropriately.
For Subtask 3 (25 marks), your opponent only throws Rock. More formally, R_{a} = N, P_{a} = 0, and S_{a} = 0.
Hint: The solution to this subtask is quite similar to subtask 2.
For Subtask 4 (20 marks), neither you nor your opponent throws Scissors. More formally, S_{a} = 0 and S_{b} = 0.
Hint: Paper will never lose, since no one ever throws Scissors. Likewise, Rock will never win.
For Subtask 5 (20 marks), no further constraints apply.
Hint: Win as many rounds as you can! Then try to draw the rest, though sometimes, you can’t avoid losing.
Privacy
statement
© Australian Mathematics Trust 2001-2022
Page generated: 2 October 2022, 10:13am AEDT