This will take more time than mine... Mine will be very fast as we are
exiting if the least sum is outside "n"

On Thu, Jul 7, 2011 at 6:56 PM, yv paramesh <yv.param...@gmail.com> wrote:

> Hi,
>
> a <--- 3Km --->b<--- 5Km --->c<--- 2Km --->d<--- 6Km -->e
>
> lets arry be 3,5,2,6,8,10,16,7,13,8    it can be any order...
>
> higest value is 16 ie total distance.
>
> now chose pairs whose sum equals to 16
> 3,13
> 6,10
> 8,8
>
> now we come to know the distance of point for either from a or e
>
> If we are able to arrange these pairs we can calculate distances.
>
> let start with pair 3,13 since 3 is least value among pairs.
>   diference of 3,6 is 3 and 3 is not in remaining list . so 10 is point
> from same end
>  differnce of 3,8 is 5 it is in remainig list so 8 is point from same end.
>
>  so it is  0 3 8 10 16
>
>  diffrence is 3 5 2 6
>
> --paramesh
>
>
> On Thu, Jul 7, 2011 at 6:00 PM, sachin sharma <sachin.bles...@gmail.com>wrote:
>
>>
>>
>> What about this:
>>
>> First you have the list of distances between two milestones. Let’s form a
>> table
>>
>> Start milestone
>>
>> End Milestone
>>
>> Distances
>>
>> A1
>>
>> A0
>>
>> 7
>>
>> A0
>>
>> A3
>>
>> 10
>>
>> A1
>>
>> A2
>>
>> 5
>>
>> A2
>>
>> A3
>>
>> 2
>>
>> A0
>>
>> A2
>>
>> 8
>>
>> A0
>>
>> A1
>>
>> 3
>>
>>
>>
>> I have taken above variable A0, A1, A2, A3 for a, b, c, d respectively.
>> Now we sort the first column. If we find two entries same then sort also on
>> based on second column.
>>
>> After processing you will get the following table
>>
>> Start milestone
>>
>> End Milestone
>>
>> Distances
>>
>> A0
>>
>> A1
>>
>> 3
>>
>> A0
>>
>> A2
>>
>> 8
>>
>> A0
>>
>> A3
>>
>> 10
>>
>> A1
>>
>> A0
>>
>> 7
>>
>> A1
>>
>> A2
>>
>> 5
>>
>> A2
>>
>> A3
>>
>> 2
>>
>>
>>
>> When you get this table:
>>
>> 1)      Start with A0 and search for next milestone which is A1. Add this
>> to your milestone list or just print.
>>
>> 2)      Move to A1 in the first column and add the first entry which does
>> not contains previously visited milestone. That is A2 whose distance is 5.
>> You cannot add A1-A0 since it is already visited.
>>
>> 3)      Repeat the above process till the end of list in table. Now
>> following this step you come to A2 and you add A3 in the milestone list
>> whose distance is 2.
>>
>> 4)       Now you get the list of milestone…and distances. Output you get
>> is 3-5-2 or 2-5-3.
>>
>> I hope this will work.
>>
>>
>>
>> Best Wishes
>> Sachin Sharma | Software Trainee | Information Mosaic
>> New York | Dublin | London | Luxembourg | New Delhi | Singapore |
>> Melbourne |
>> e-mail: sachinku...@informationmosaic.com
>> Web:www.informationmosaic.com<http://www.informationmosaic.com/> |  t:
>> www.twitter.com/infomosaic
>> Winner 2009 Banking Technology Readers' Choice Award for Best Corporate
>> Actions Automation Solution
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to