Page 1 of 2

10935 - Throwing cards away I

Posted: Sun Oct 16, 2005 12:12 am
by mmij
can anybody give me some critical input & output???

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

Posted: Sun Oct 16, 2005 12:40 am
by Jan
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.

Posted: Sun Oct 16, 2005 1:00 am
by mmij
thanks Jan. i didn't consider for n=1. now got acc :D :D

No one.

Posted: Mon Oct 17, 2005 9:09 pm
by _.B._
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! 8)

Posted: Mon Oct 17, 2005 9:49 pm
by little joey
According to MathWorld, a sequence is an ordered set, and a set can be empty, so a sequence can be empty. So, IMO, n=1 is perfectly valid, leading to an empty sequence and a remaining card.

MathWorld.

Posted: Tue Oct 18, 2005 5:59 am
by _.B._
I guess I shlould check MathWorld more often 8)
Since they only give the operation to be performed as long as there are at least two cards in the deck, I guess it's an easy task for everyone to have to imagine how it should work for the case where there is only one card.

Keep posting!

Posted: Wed Apr 25, 2007 10:26 am
by Steven Luck
Can anyone help me? I get PE. I've tried handling the output if the input is n = 1.

Here's my code:

Code: Select all

      Code removed after Accepted.
Thanks.

abt pe..

Posted: Wed Apr 25, 2007 10:48 pm
by Rocky
To Steven Luck

u done a simple mistake..the problem says that to print new line after every test case that is u not done..u print new line after every test case but except the last case...
correct it & i think then it will ok.....

btw:remove ur code after correction...

GOOD LUCK
Rocky

Posted: Thu Apr 26, 2007 7:32 am
by Steven Luck
I thought I've tried that one - printing a new line after each problem - but it didn't work. But then, after seeing your post, I try printing a new line again, and it worked! :D

Thanks, Rocky.

Posted: Wed Jun 20, 2007 1:51 am
by ankit.arora
i am getting PE but the output seems to be in order..... please help!!

Code: Select all

CODE REMOVED AFTER AC  

Posted: Thu Jun 21, 2007 1:28 am
by Jan
For n=1 the output should be

Code: Select all

Discarded cards:<- No space here, but your code has one
Remaining card: 1
Hope it helps.

Posted: Fri Jun 22, 2007 9:55 pm
by ankit.arora
Thanks a lot.... got AC!

Re: No one.

Posted: Tue Aug 17, 2010 2:51 pm
by angrad
_.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! 8)
I agree with U absolutely! :D

Re:

Posted: Sun Feb 13, 2011 7:18 am
by abid_iut
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.
thanks jan vai

Re: 10935 - Throwing cards away I

Posted: Tue Mar 15, 2011 9:01 pm
by DD

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
This is the output for n = 50. If you got W.A. on this problem, you can test this. :)