Thread: Need help understanding problem with arrays

  1. #1
    Registered User
    Join Date
    Nov 2009
    Location
    Italy
    Posts
    65

    Need help understanding problem with arrays

    Hi guys, I'm reading this problem which I find quite confusing, here it is:
    "We are in 2100 and we can travel universe, the α1λ3 course links the Earth to Saturn and spaceships are obliged to follow it taking several years to get through it. In order to watch the spaceships in their course, the first day of each month of each year are calculated the covered light year distance from the earth, if the spaceship takes off from the earth, and the light year distance left to get to the earth if the spaceship takes off from Saturn. Suppose that the two spaceships travel at different velocity and have taken off at the same time, the first from the earth and the second from Saturn on the 1st of January of the same year ( N ), and have got to their destination the 1st of January of the year M1 the former, and the 1st of January of the year M2 the latter. (M1, M2 > N).
    DA and DB are two arrays that contain the distances covered by the two spaceships, given the three years (N, M1, M2), find in which year and in which month the two spaceships have crossed each other.

    Example:
    for a given year N the two arrays are:
    DA
=
[0,
0.5
,
0.7
,
1.2,
1.5,
2]

    DB
=
[2,
1.7,
1.3,
0.9,
0.4,
0.24,
0]

    and the two spaceships crossed in April (the 4th month) of the year N

    Guys this is not an homework, I'm not asking anyone to solve it, I just need to understand the mathematical concept behind it, i made some graphs but I couldn't figure out its logic, any tip would be appreciate, thanks anyway
    Last edited by rob90; 02-26-2010 at 06:21 AM.

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    The best thing to do with these word problems, is to grab a pencil and paper, and draw them out. The basic equation to remember is:

    Distance = Rate * Time

    but here, they're giving you the distances traveled in each month, for each spaceship. That's your key. When the amount that has been traveled by the faster spaceship, is greater than the distance remaining for the slower spaceship, then the two spaceships have crossed.

    Take a few "snapshots" of the spaceships along the way, their distances traveled, and the distance still to be traveled, and see if that makes sense.

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    48
    If x1 is the distance from earth for DA traveling to Saturn and x2 be the distance traveled by DB, whose distance from earth is given by x2, then the distance traveled by DB from Saturn is given by : DISTANCE_BETWEEN_EARTH_AND_SATURN - x2.

    When
    (x1 + (DISTANCE_BETWEEN_EARTH_AND_SATURN - x2) >= DISTANCE_BETWEEN_EARTH_AND_SATURN)
    the 2 space ships have crossed each other, but since statistics are available only at the beginning of each month,
    for : DA[3] + (2 - DB[3]) >= 2
    hence the 2 space ships have crossed each other.ie 4th month.

    Hope i haven't misunderstood the question. Do you have more test cases.

  4. #4
    Registered User
    Join Date
    Nov 2009
    Location
    Italy
    Posts
    65
    I finally get it, it wasn't difficult at all, thanks again!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointers to arrays problem
    By key4life in forum C Programming
    Replies: 11
    Last Post: 02-13-2010, 05:56 PM
  2. help understanding arrays of strings!
    By smoking81 in forum C Programming
    Replies: 18
    Last Post: 02-23-2008, 04:24 AM
  3. Help Understanding Passing Arrays To Functions
    By jrahhali in forum C++ Programming
    Replies: 7
    Last Post: 04-10-2004, 02:57 PM
  4. Problem with character arrays in classes
    By spoketoosoon in forum C++ Programming
    Replies: 3
    Last Post: 03-16-2004, 03:57 AM
  5. Help understanding arrays and pointers
    By James00 in forum C Programming
    Replies: 2
    Last Post: 05-27-2003, 01:41 AM