I think you can do an exhaustive search, with quick completion, this is not as bad as it seems.
For example, if you select a number from A and B, you can select two numbers from C that are closest to these two numbers, using any other number may not give better results.
- For each element A: name it
a , you are looking for numbers close to the interval (a, a) - Now, for each group, select the closest numbers (you can do this with binary search). Now you have a new search interval, either (a, b1) or (b2, a)
Example:
- Choose 4 from A, going close to (4.4)
- A) Choose 2 from B, going close to (2,4)
- .... Select 3 from C, this is in the interval. search near (2.4)
- .... Choose 7 from D, interval (2.7), distance 5.
- B) Choose 6 from B, look close to (4.6)
- ....
Karoly Horvath
source share