You are viewing a single comment's thread. Return to all comments →
static int whoGetsTheCatch(int n, int x, int[] X, int[] V){ float[] times = new float[n]; int minPosition = -1; int numAtMin = 0; for (int i = 0 ; i < n ; i++) { times[i] = Math.abs((float) X[i]-x) / V[i]; if (minPosition == -1 || times[i] < times[minPosition]) { minPosition = i; numAtMin = 1; } else if (times[i] == times[minPosition]) { numAtMin++; } } return numAtMin == 1 ? minPosition: -1; }
Seems like cookies are disabled on this browser, please enable them to open this website
Who Gets the Catch?
You are viewing a single comment's thread. Return to all comments →