should i consider negative value??
can it be n=1??
i've solved this problem using stl queue.....but getting wa

Moderator: Board moderators
Code: Select all
1
10
11
17
0
Code: Select all
Discarded cards:
Remaining card: 1
Discarded cards: 1, 3, 5, 7, 9, 2, 6, 10, 8
Remaining card: 4
Discarded cards: 1, 3, 5, 7, 9, 11, 4, 8, 2, 10
Remaining card: 6
Discarded cards: 1, 3, 5, 7, 9, 11, 13, 15, 17, 4, 8, 12, 16, 6, 14, 10
Remaining card: 2
I believe input n = 1 is contradictory to the statement of the problem.The following operation is performed as long as there are at least two cards in the deck:
Throw away the top card and move the card that is now on the top of the deck to the bottom of the deck.
Your task is to find the sequence of discarded cards and the last, remaining card.
Code: Select all
Code removed after Accepted.
Code: Select all
CODE REMOVED AFTER AC
Code: Select all
Discarded cards:<- No space here, but your code has one
Remaining card: 1
I agree with U absolutely!_.B._ wrote:Greetings!
I believe input n = 1 is contradictory to the statement of the problem.The following operation is performed as long as there are at least two cards in the deck:
Throw away the top card and move the card that is now on the top of the deck to the bottom of the deck.
Your task is to find the sequence of discarded cards and the last, remaining card.
They ask you to find a sequence of discarded cards, and a remaining card. With n = 1 there is no sequence of discarded cards, therefore there can be no remaining card, and also, you should work this problem with "at least two cards".
It's only my opinion.
Keep posting!
thanks jan vaiJan wrote:There is no negative values for n. But n can be 1.
You can try the following input output set.
Input:Output:Code: Select all
1 10 11 17 0
Hope it helps.Code: Select all
Discarded cards: Remaining card: 1 Discarded cards: 1, 3, 5, 7, 9, 2, 6, 10, 8 Remaining card: 4 Discarded cards: 1, 3, 5, 7, 9, 11, 4, 8, 2, 10 Remaining card: 6 Discarded cards: 1, 3, 5, 7, 9, 11, 13, 15, 17, 4, 8, 12, 16, 6, 14, 10 Remaining card: 2
Code: Select all
50
0
Code: Select all
Discarded cards: 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 2, 6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 8, 16, 24, 32, 40, 48, 12, 28, 44, 20, 4
Remaining card: 36