On Tue, Sep 1, 2009 at 8:19 AM, Luke Pebody<[email protected]> wrote:
>
> Let us label the fifteen cards in the order they start A, B, ... , O.
> So the initial order is ABCDEFGHIJKLMNO. The top card (A) is picked,
> and then the next card (B) is put to the bottom of the pack so the
> order is now CDEFGHIJKLMNOB. Now the top card (C) is picked and the
> next two cards (D,E) are put to the bottom so the order is
> FGHIJKLMNOBDE.

You are right but i cannot understand why this process is ending to
the solution.
I solved the problem only for the small input because my solution seems to be
too slow. I found another player using your algorithm but i cannot
understand it.
Here is my solution:

for case in xrange(input()):
  cards = input()
  indexes = map(int, raw_input().split())

  deck = [0 for i in xrange(cards)]
  index = -1
  for i in xrange(1, cards + 1):
    while True:
      index = (index + 1)%cards
      if deck[index] == 0:
        break
    for j in xrange(i - 1):
      while True:
        index = (index + 1)%cards
        if deck[index] == 0:
          break
    deck[index] = i

  print 'Case #%d: %s' % (case + 1, ' '.join(str(deck[i - 1])
                                                 for i in indexes[1:]))

Basically i start placing cards skipping placing in order to reach
the n-th position(i should ignore the places in which i have already
placed another card):
1 - - - -
1- 2 - -
1 3 2 - -
1 3 2 - 4
1 3 2 5 4

> This continues, and after transferring cards to the bottom, the orders
> are: JKLMNOBDEGHI, OBDEGHIKLMN, IKLMNBDEGH, EGHKLMNBD, DGHKLMNB,
> HKLMNBG, NBGKLM, BGKLM, MGKL, GKL, LK, K. Thus the cards are pulled
> off in the order ACFJO then IEDHN then BMGLK. The question asks in
> what order the original 3rd, 4th, 7th and 10th cards are pulled off.
> These are C, D, G and J, and were pulled off 2nd, 8th, 13th and 4th
> respectively.
>
> On 31 Aug 2009, at 05:37, "parashar.ankur" <[email protected]>
> wrote:
>
>>
>> for the Input Case..
>> Input
>> 2
>> 5
>> 5 1 2 3 4 5
>> 15
>> 4 3 4 7 10
>>
>> the output is
>>
>> Output
>> Case #1: 1 3 2 5 4
>> Case #2: 2 8 13 4
>>
>> i got the case 1 bt unable to understand case2 somebody tell me in
>> detail my be i'm getting this question wrong.
>>
>> >
>
> >
>



-- 
M@
http://matteolandi.altervista.org/

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"google-codejam" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-code?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to