## 10935 - Throwing cards away I

Moderator: Board moderators

### 10935 - Throwing cards away I

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
mmij
New poster

Posts: 10
Joined: Mon Jul 11, 2005 7:13 am
Location: PlanetEarth

There is no negative values for n. But n can be 1.

You can try the following input output set.

Input:
Code: Select all
`11011170`

Output:
Code: Select all
`Discarded cards:Remaining card: 1Discarded cards: 1, 3, 5, 7, 9, 2, 6, 10, 8Remaining card: 4Discarded cards: 1, 3, 5, 7, 9, 11, 4, 8, 2, 10Remaining card: 6Discarded cards: 1, 3, 5, 7, 9, 11, 13, 15, 17, 4, 8, 12, 16, 6, 14, 10Remaining card: 2`

Hope it helps.
Ami ekhono shopno dekhi...
HomePage
Jan
Guru

Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm

thanks Jan. i didn't consider for n=1. now got acc
mmij
New poster

Posts: 10
Joined: Mon Jul 11, 2005 7:13 am
Location: PlanetEarth

### No one.

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.

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!
[color=darkgreen][b]_.

_.B._
Experienced poster

Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela

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.

little joey
Guru

Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

### MathWorld.

I guess I shlould check MathWorld more often
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!
[color=darkgreen][b]_.

_.B._
Experienced poster

Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela

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.
Last edited by Steven Luck on Thu Apr 26, 2007 7:33 am, edited 1 time in total.
"The Only Thing For The Triumph of Evil is For a Good Man to Do Nothing"
Steven Luck
New poster

Posts: 13
Joined: Sat Dec 02, 2006 7:51 am
Location: Indonesia

### abt pe..

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

Rocky
Experienced poster

Posts: 124
Joined: Thu Oct 14, 2004 9:05 am

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!

Thanks, Rocky.
"The Only Thing For The Triumph of Evil is For a Good Man to Do Nothing"
Steven Luck
New poster

Posts: 13
Joined: Sat Dec 02, 2006 7:51 am
Location: Indonesia

Code: Select all
`CODE REMOVED AFTER AC  `
Last edited by ankit.arora on Fri Jun 22, 2007 9:57 pm, edited 1 time in total.
ankit.arora
New poster

Posts: 11
Joined: Tue May 22, 2007 10:09 pm
Location: India

For n=1 the output should be

Code: Select all
`Discarded cards:<- No space here, but your code has oneRemaining card: 1`

Hope it helps.
Ami ekhono shopno dekhi...
HomePage
Jan
Guru

Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm

Thanks a lot.... got AC!
ankit.arora
New poster

Posts: 11
Joined: Tue May 22, 2007 10:09 pm
Location: India

### Re: No one.

_.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.

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!

I agree with U absolutely!
New poster

Posts: 3
Joined: Tue Aug 17, 2010 9:58 am

### Re:

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
`11011170`

Output:
Code: Select all
`Discarded cards:Remaining card: 1Discarded cards: 1, 3, 5, 7, 9, 2, 6, 10, 8Remaining card: 4Discarded cards: 1, 3, 5, 7, 9, 11, 4, 8, 2, 10Remaining card: 6Discarded cards: 1, 3, 5, 7, 9, 11, 13, 15, 17, 4, 8, 12, 16, 6, 14, 10Remaining card: 2`

Hope it helps.

thanks jan vai
i love to wait... wait for better... and better will come...
http://akanoi.webs.com/
abid_iut
Learning poster

Posts: 80
Joined: Wed Jul 16, 2008 7:34 am

### Re: 10935 - Throwing cards away I

Code: Select all
`500`

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, 4Remaining card: 36`

This is the output for n = 50. If you got W.A. on this problem, you can test this.
Have you ever...

Wanted to work at best companies?
Struggled with interview problems that could be solved in 15 minutes?
Wished you could study real-world problems?
If so, you need to read Elements of Programming Interviews.
DD
Experienced poster

Posts: 145
Joined: Thu Aug 14, 2003 8:42 am
Location: Mountain View, California

Next