You are not logged in.
Pages: 1
hi guys
You are given a set of points {(x1, y1), (x2, y2), ..., (xn, yn)}. You should compute the smallest menhetn distance between all the pairs of the points.
Menhetn distance between two points (a, b) and (c, d) is defined as |a - c| + |b - d|.
INPUT:
In the first line of the standard input is given an integer n (2 <= n <= 1000). In the next n lines are given the points -- in the i-th is given the point (xi, yi) (-100000 <= xi, yi <= 100000), where both xi and yi are integers.
OUTPUT:
In the first and the only line of the standard output you should print the smallest distance.
Here lies the reader who will never open this book. He is forever dead.
Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment
The knowledge of some things as a function of age is a delta function.
Offline
So menhetn distance as anoni has mentioned would be like walking along blocks in a big city, you can't go diagonally,
but only follow x and y to get there and then compute the distance. Very simple, much easier, no pythagoean theorem.
igloo myrtilles fourmis
Offline
I suppose this could be similar to Manhattan distance?
igloo myrtilles fourmis
Offline
Hi;
Yes, he means manhattan distance.
Take and form two loops to generate all possible pairs and then use the formula for manhattan distance on each pair. Use one variable as the holder for the smallest found so far.
In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.
Offline
hi bobbym
that was my first thought,but it takes more time than it should.is there a relation that calculates the minimum Manhattan distance of three points?maybe then i can expand it for more points.
Here lies the reader who will never open this book. He is forever dead.
Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment
The knowledge of some things as a function of age is a delta function.
Offline
I disagree, you are asked to find the smallest from all possible pairs of points. How can that be expanded?
In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.
Offline
yes,but i meant that maybe there's a formula that calculates that minimum distance for 3 points.then it could be used for the task.
Here lies the reader who will never open this book. He is forever dead.
Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment
The knowledge of some things as a function of age is a delta function.
Offline
Not without trying each pair of points. Let's assume such a formula exists. For two points it has 2 variables for 3 probably 3 variables for 10000 points maybe 10000 variables. I do not think it has been discovered.
In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.
Offline
no,i just need for three.
Here lies the reader who will never open this book. He is forever dead.
Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment
The knowledge of some things as a function of age is a delta function.
Offline
Okay, you have lost me. Three what?
In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.
Offline
three points.i just want some way to find the minimum Man. distance for three points.
Here lies the reader who will never open this book. He is forever dead.
Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment
The knowledge of some things as a function of age is a delta function.
Offline
I doubt that there is anything simpler than trying all 3 pairs of points. At least I have never heard of it.
In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.
Offline
Yeah, just try all three like this in BASIC:
jFinished = 18
abs(ax - bx) + abs(ay - by) = mAB
abs(ax - cx) + abs(ay - cy) = mAC
abs(bx - cx) + abs(bx - cy) = mBC
''find the smallest of the three
if (mAB = mAC) then
if (mAB = mBC) then
print "All three distances are the same and are: ";mBC
jFinished = 22
end if
end if
if (18 = jFinished) then
if (mAB = mAC) then
if (mBC < mAB) then
print "distance BC is the smallest and is: "; mBC
jFinished = 22
else
print "distance AB and AC are the smallest and are equal and are: "; mAB
jFinished = 22
end if
end if
if (mAB = mBC) then
if (mAC < mBC) then
print "distance AC is the smallest and is: "; mAC
jFinished = 22
else
print "distance AB and BC are the smallest and are equal and are: "; mAB
jFinished = 22
end if
end if
if (mAC = mBC) then
if (mAB < mBC) then
print "distance AB is the smallest and is "; mAB
jFinished = 22
else
print "distance AC and BC are the smallest and are equal and are: "; mBC
jFinished = 22
end if
end if
end if
'''comment: All 3 distances are different below here.
if (18 = jFinished) then
if (mAB < mAC) then
if (mAB < mBC) then
print "distance AB is the smallest and is: "; mAB
jFinished = 22
end if
end if
if (mAC < mBC) then
if (mAC < mAB) then
print "distance AC is the smallest and is: "; mAC
jFinished = 22
end if
end if
if (mBC < mAB) then
if (mBC < mAC) then
print "distance BC is the smallest and is: "; mBC
jFinished = 22
end if
end if
end if
if (18 = jFinished) then
print "Something is wrong with the program or the software."
end if
''(end of file)
''EOF
Last edited by John E. Franklin (2012-01-27 12:58:18)
igloo myrtilles fourmis
Offline
Pages: 1