WolfCardGame
SRM 690 · 2016-05-02 · by tozangezan
SRM 690 · 2016-05-02 · by tozangezan · Simple Math
Problem Statement
Problem Statement
Wolf Sothe and Cat Snuke are playing a card game.
The game is played with exactly 100 cards.
The cards are numbered from 1 to 100.
The game is played as follows:
Your task is to help Wolf Sothe win the game. We are now in step 2 of the game. You are given theint N chosen by Snuke and the int K that specifies the number of cards you have to give to Snuke.
Choose those K cards in such a way that Snuke will be unable to win the game.
If you can do that, return a int[] with K elements: the numbers on the chosen cards.
If there are multiple solutions, you may return any of them.
If there is no solution, return an empty int[] instead.
- First, Cat Snuke chooses the goal: an integer N between 1 and 100, inclusive.
- Then, Wolf Sothe chooses exactly K of the 100 cards and gives the chosen cards to Snuke.
- Next, Cat Snuke may throw some of those K cards away. He may choose any subset of cards he was given, possibly none or all of them.
- Finally, Cat Snuke may write minus signs onto any subset of the cards he still holds. For example, if he currently has the cards {1,3,4,7}, he may alter them to {-1,3,4,-7}.
Your task is to help Wolf Sothe win the game. We are now in step 2 of the game. You are given the
Constraints
- N will be between 1 and 100, inclusive.
- K will be between 1 and 15, inclusive.
Examples
0)
20
4
Returns: {1, 2, 3, 4 }
If we give Snuke cards with numbers 1, 2, 3, and 4 on them, the largest sum he can form is 1+2+3+4 = 10. Thus, he cannot reach N=20 and we win.
1)
40
1
Returns: {39 }
2)
97
6
Returns: {7, 68, 9, 10, 62, 58 }
3)
2
12
Returns: {33, 69, 42, 45, 96, 15, 57, 12, 93, 9, 54, 99 }
4)
100
15
Returns: {6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90 }
Submissions are judged against all 136 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class WolfCardGame with a public method vector<int> createAnswer(int N, int K) · 136 test cases · 2 s / 256 MB per case