Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0939859

Browse files
commit
1 parent 5d13604 commit 0939859

File tree

3 files changed

+35
-36
lines changed

3 files changed

+35
-36
lines changed

‎FastClosestPoint2D/.idea/workspace.xml

Lines changed: 28 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎FastClosestPoint2D/src/com/xplore/solutions/ClosestPoint2D.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ public static double brute(Point2d[] array, int lo, int hi) {
6262
/**
6363
* n log(n)
6464
* */
65-
private static double solver(Point2d[] orderByX, Point2d[] aux, int hi) {
65+
private static double solver(Point2d[] orderByX, Point2d[] aux, int lo, inthi) {
6666
if(hi <= 3)
67-
return brute(orderByX, 0, hi);
67+
return brute(orderByX, lo, hi);
6868
int mid = hi/2;
69-
double left = solver(orderByX, aux, mid);
70-
double right = solver(orderByX, aux, hi - mid);
69+
double left = solver(orderByX, aux, 0, mid);
70+
double right = solver(orderByX, aux, mid+1, hi - mid);
7171
double currentMin = Math.min(left, right);
7272
int k = 0;
7373
for (int i = 0; i < hi ; i++) {
@@ -187,20 +187,19 @@ else if(k == 2) {
187187
,new Point2d(1, -1)
188188
}
189189
,{
190-
new Point2d(0, 3)
190+
new Point2d(0, 3)
191191
,new Point2d(3, 4)
192192
,new Point2d(4, 2)
193193
,new Point2d(-2, 1)
194194
,new Point2d(1, -1)
195195
}
196196
,{
197-
new Point2d(0, 2)
197+
new Point2d(0, 2)
198198
,new Point2d(6, 67)
199199
,new Point2d(43, 71)
200200
,new Point2d(39, 107)
201201
,new Point2d(189, 140)
202202
}
203-
204203
};
205204

206205
public static void test() {
@@ -209,7 +208,7 @@ public static void test() {
209208
System.arraycopy(matrix[idx], 0, points, 0, points.length);
210209
Arrays.sort(points, SORT_BY_X);
211210

212-
double min = solver(points, new Point2d[points.length], points.length);
211+
double min = solver(points, new Point2d[points.length], 0, points.length);
213212
System.out.println(min);
214213

215214
Point2d [] pQ = solver2(points, new Point2d[points.length], points.length);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /