Thread: Problem - 2 elevators, when do they meet ?

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    76

    Problem - 2 elevators, when do they meet ?

    Hi, I have such problem: there is 2 elevators in a one building of x floors, they drive only upwards. And we have such data (for example):
    1. elevator:
    a1=1
    r=3
    2. elevator
    a1=2
    r=4

    a1 is a numer of the floor from which each elevator starts and r is a period of an elevator breaks - for example, second elevator starts on the 2nd floor, then it stops on the 6h, 10th, 14th and so on and so forth. And here is my question, how to calculate the lowest number of the floor on which two elevators meets and what the period would be? I know that they will meet when GCD(r_1,r_2)|p where p is |a1_1 - a1_2|.
    Regards,
    apacz

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I'm not quite sure why you're posting your homework on the contests board... Consider this your lucky day.
    Code:
    for( e1 = start1, e2 = start2; e1 != e2; )
    {
        while( e1 < e2 )
            e1 += increment1;
        while( e2 < e1 )
            e2 += increment2;
    }
    Yeah, that looks about right.


    Quzah.
    Last edited by quzah; 12-03-2005 at 11:50 AM. Reason: Lucky day.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  2. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM