Dieser ist schnell, aber nicht die minimale Anzahl von Punkten. Beachten Sie, dass die Schleife Änderungen verarbeiten muss, um S festzulegen, wenn ein Punkt entfernt oder inaktiviert wird.
For each Point P1 in S
{
For each Point P2 after P1 in S
{
If (square(P1.x - P2.x) + square(P1.y - P2.y) < square(R))
{
remove (P2)
}
}
}
Für Minimum, aber teuer:
use double loop to store each P2 closest to P1
example: array [P1][P2]
Sort array based on size of array [P1].numOfElements()
such that largest is at the top
now remove top element P from set S
and in array P1
and all subsequent P in P2 of all P1
If P2 is empty for any element X in P1 then remove it
Remove the next top element and do the process again until array is empty
Resulting set is the answer for minimum points
Wenn es nur zwei Punkte und der Abstand kleiner als R, würde das Ergebnis in 0 Punkten? – Striker
@Striker 1 Punkt entfernen. Sie haben jetzt einen Punkt übrig und es hat keinen anderen Punkt näher als R. –
@Striker Ich denke schon. Es sollte leer gesetzt werden – GilbertLee