should i consider negative value??
can it be n=1??
i've solved this problem using stl queue.....but getting wa
Moderator: Board moderators
1
10
11
17
0Discarded 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: 2The 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 removed after Accepted.

CODE REMOVED AFTER AC Discarded cards:<- No space here, but your code has one
Remaining card: 1_.B._ wrote:Greetings!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.
I believe input n = 1 is contradictory to the statement of the problem.
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!
Jan wrote:There is no negative values for n. But n can be 1.
You can try the following input output set.
Input:
- Code: Select all
1
10
11
17
0
Output:
- 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
Hope it helps.
50
0
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
Users browsing this forum: No registered users and 0 guests