MCPcopy Create free account
hub / github.com/algorithmzuo/algorithm-journey / best

Method best

src/class129/Code05_RoadTrip.java:167–181  ·  view source on GitHub ↗
(int x0)

Source from the content-addressed store, hash-verified

165 }
166
167 public static int best(int x0) {
168 int ans = 0;
169 double min = Double.MAX_VALUE;
170 double cur;
171 for (int i = 1; i < n; i++) {
172 travel(i, x0);
173 // cur这么设置更安全一些
174 cur = b == 0 ? Double.MAX_VALUE : ((double) a / (double) b);
175 if (ans == 0 || cur < min || (cur == min && arr[i] > arr[ans])) {
176 ans = i;
177 min = cur;
178 }
179 }
180 return ans;
181 }
182
183 public static int a, b;
184

Callers 1

mainMethod · 0.95

Calls 1

travelMethod · 0.95

Tested by

no test coverage detected