Connection Status:
Competition Arena > WolfCardGame
SRM 690 · 2016-05-02 · by tozangezan · Simple Math
Class Name: WolfCardGame
Return Type: int[]
Method Name: createAnswer
Arg Types: (int, int)
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:
  1. First, Cat Snuke chooses the goal: an integer N between 1 and 100, inclusive.
  2. Then, Wolf Sothe chooses exactly K of the 100 cards and gives the chosen cards to Snuke.
  3. 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.
  4. 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}.
At the end of the game, Snuke computes the sum of the numbers on his cards (with the added minus signs). Snuke wins the game if the sum is exactly equal to the goal number N. Otherwise, Sothe wins.

Your task is to help Wolf Sothe win the game. We are now in step 2 of the game. You are given the int 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.

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

Submitting as anonymous