#P13462. [GCJ 2008 #1B] Mousetrap

[GCJ 2008 #1B] Mousetrap

题目描述

Mousetrap is a simple card game for one player. It is played with a shuffled deck of cards numbered 11 through KK, face down. You play by revealing the top card of the deck and then putting it on the bottom of the deck, keeping count of how many cards you have revealed. If you reveal a card whose number matches the current count, remove it from the deck and reset the count. If the count ever reaches K+1K+1, you have lost. If the deck runs out of cards, you win.

Suppose you have a deck of 55 cards, in the order 2,5,3,1,42, 5, 3, 1, 4. You will reveal the 22 on count 11, the 55 on count 22, then the 33 on count 33. Since the value matches the count, you remove the 33 from the deck, and reset the count. You now have 44 cards left in the order 1,4,2,51, 4, 2, 5. You then reveal the 11 on count 11, and remove it as well (you're doing great so far!). Continuing in this way you will remove the 22, then the 44, and then finally the 55 for victory.

You would like to set up a deck of cards in such a way that you will win the game and remove the cards in increasing order. We'll call a deck organized in this way "perfect." For example, with 44 cards you can organize the deck as 1,4,2,31, 4, 2, 3, and you will win by removing the cards in the order 1,2,3,41, 2, 3, 4.

输入格式

The first line of input gives the number of cases, TT. Each test case starts with a line containing KK, the number of cards in a deck. The next line starts with an integer nn, which is followed by nn integers (d1,d2,)(d_1, d_2, \ldots), indices into the deck.

输出格式

For each test case, output one line containing "Case #xx: " followed by nn integers (k1,k2,)(k_1, k_2, \ldots), where kik_i is the value of the card at index did_i of a perfect deck of size KK. The numbers in the output should be separated by spaces, and there must be at least one space following the colon in each "Case #xx: " line.

2
5
5 1 2 3 4 5
15
4 3 4 7 10
Case #1: 1 3 2 5 4
Case #2: 2 8 13 4

提示

Small dataset (15 Pts, Test set 1 - Visible)

  • Time limit: 60 6 seconds.
  • T=100,T = 100,
  • 1K5000,1 \leq K \leq 5000,
  • 1n100,1 \leq n \leq 100,
  • 1diK.1 \leq d_i \leq K.

Large dataset (Test set 2 - Hidden)

  • Time limit: 180 18 seconds.
  • T=10,T = 10,
  • 1K1000000,1 \leq K \leq 1000000,
  • 1n100,1 \leq n \leq 100,
  • 1diK.1 \leq d_i \leq K.