I'm trying to solve a minimal tree problem, where I try to find the minimum path to connect all of us. The nodes represent objects with position defined by x, y (integers) in space, so I find the distance between one and the other by the following excerpt:
dist = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2))
As I mentioned above, x
and y
are integers and the end result must be double
with the sum of the path that travels the shortest distance to join all nodes.
What is happening is that my results are always giving similar values, however, not exact to what the system requires and my answer is not accepted.
Ex:
Program Exit: 98.00 Expected Exit: 98.02
How can I improve accuracy in final numbers?