Party Algorithm
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Party Algorithm

Hybrid View

  1. #1
    Join Date
    Oct 2012
    Posts
    1

    Party Algorithm

    I have got problem with this task from my university algorithm course (translated from german):

    > John have got a party. He prepared $x$ glasses of vodka and $k*x$
    > glasses of rum.
    >
    > Number of glasses is n. Each guests drink one
    > round of alcohol (one round is $k$ glasses of rum and $one$ of vodka) but
    > guest must chose glass that every full glass must have got one full
    > neighbor.
    >
    > Write the program which simulate John's party. The party ends when all
    > glasses are empty.
    >
    > In input we have got $n$ and $k$ which means number of glasses and number
    > of glasses of rum drunk in single turn).

    Simple Input : (assume that r is rum and v - vodka ).

    > 16 3 vvrrrvrvrrrrrrrr

    Simple Output : (we numbered glass 1...n)

    > 1 14 15 16
    > 2 11 12 13
    > 3 4 5 6
    > 7 8 9 10

    Explain :

    Guest 1 drink 1, 14, 15 and 16 glass.
    Guest 2 drink 2, 11, 12, 13 glass.
    etc.

    We write it in ascending order. Notice that we have got $\frac{n}{(k+1)}$ guests, $n$ glasses, $k$ glasses of rum in every round. And in all inputs $k+1$ divides $n$. And $n$ can be very big - about 2 000 000. And we have about 1-2s to answer the question.

    Find the fastest as possible algorithm to solve this problem.

    Thanks for every help. If you have got any questions, i will answer it.
    Edger.

  2. #2
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,642

    Re: Party Algorithm

    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    http://www.microsoft.com/visualstudio/eng/downloads

  3. #3
    Join Date
    May 2009
    Posts
    2,413

    Re: Party Algorithm

    Quote Originally Posted by Edger521 View Post
    Thanks for every help. If you have got any questions, i will answer it.
    I'm slightly Lost in Translation. Could you please post the German original.

    Is this an algorithmic problem or is it a question of writing a simulation program to study an algorithm. If it's the latter I wouldn't expect anyone to supply such a program.

    Have you tried something yourself? Some effort on your part is expected.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center