10935 - Throwing cards away I

All about problems in Volume 109. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

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

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

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:
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.
Ami ekhono shopno dekhi...
HomePage

mmij
New poster
Posts: 10
Joined: Mon Jul 11, 2005 7:13 am
Location: PlanetEarth
thanks Jan. i didn't consider for n=1. now got acc

_.B._
Experienced poster
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela
Contact:

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.

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

little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm
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.

_.B._
Experienced poster
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela
Contact:

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

Steven Luck
New poster
Posts: 13
Joined: Sat Dec 02, 2006 7:51 am
Location: Indonesia
Contact:
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"

Rocky
Experienced poster
Posts: 124
Joined: Thu Oct 14, 2004 9:05 am
Contact:

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

Steven Luck
New poster
Posts: 13
Joined: Sat Dec 02, 2006 7:51 am
Location: Indonesia
Contact:
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"

ankit.arora
New poster
Posts: 11
Joined: Tue May 22, 2007 10:09 pm
Location: India
i am getting PE but the output seems to be in order..... please help!!

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.

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:
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.
Ami ekhono shopno dekhi...
HomePage

ankit.arora
New poster
Posts: 11
Joined: Tue May 22, 2007 10:09 pm
Location: India
Thanks a lot.... got AC!

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

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.

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!
I agree with U absolutely!

abid_iut
Learning poster
Posts: 82
Joined: Wed Jul 16, 2008 7:34 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

``````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
i love to wait... wait for better... and better will come...
http://akanoi.webs.com/

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

Re: 10935 - Throwing cards away I

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