10935 - Throwing cards away I

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

Moderator: Board moderators

10935 - Throwing cards away I

Postby mmij » Sun Oct 16, 2005 12:12 am

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

Postby Jan » Sun Oct 16, 2005 12:40 am

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
Jan
Guru
 
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh

Postby mmij » Sun Oct 16, 2005 1:00 am

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

No one.

Postby _.B._ » Mon Oct 17, 2005 9:09 pm

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)
[color=darkgreen][b]_.
User avatar
_.B._
Experienced poster
 
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela

Postby little joey » Mon Oct 17, 2005 9:49 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.
User avatar
little joey
Guru
 
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

MathWorld.

Postby _.B._ » Tue Oct 18, 2005 5:59 am

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!
[color=darkgreen][b]_.
User avatar
_.B._
Experienced poster
 
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela

Postby Steven Luck » Wed Apr 25, 2007 10:26 am

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

Postby Rocky » Wed Apr 25, 2007 10:48 pm

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
User avatar
Rocky
Experienced poster
 
Posts: 124
Joined: Thu Oct 14, 2004 9:05 am

Postby Steven Luck » Thu Apr 26, 2007 7:32 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! :D

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

Postby ankit.arora » Wed Jun 20, 2007 1:51 am

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.
ankit.arora
New poster
 
Posts: 11
Joined: Tue May 22, 2007 10:09 pm
Location: India

Postby Jan » Thu Jun 21, 2007 1:28 am

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
Jan
Guru
 
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh

Postby ankit.arora » Fri Jun 22, 2007 9:55 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.

Postby angrad » Tue Aug 17, 2010 2:51 pm

_.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
angrad
New poster
 
Posts: 3
Joined: Tue Aug 17, 2010 9:58 am

Re:

Postby abid_iut » Sun Feb 13, 2011 7:18 am

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

Re: 10935 - Throwing cards away I

Postby DD » Tue Mar 15, 2011 9:01 pm

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.
DD
Experienced poster
 
Posts: 145
Joined: Thu Aug 14, 2003 8:42 am
Location: Mountain View, California

Next

Return to Volume CIX

Who is online

Users browsing this forum: No registered users and 0 guests

cron