-
Notifications
You must be signed in to change notification settings - Fork 2
/
getTheCatch.java
53 lines (48 loc) · 1.35 KB
/
getTheCatch.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package easy;
import java.util.*;
public class getTheCatch {
static int whoGetsTheCatch(int n, int x, int[] X, int[] V){
double [] res = new double[n];
for(int i=0;i<n;i++){
X[i]=Math.abs(x-X[i]);
}
for(int i=0;i<n;i++){
res[i]=(X[i]/V[i]);
}
double min=res[0];
int pos=0;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if((int)res[i]==(int)res[j]&&i!=j){
pos=-1;
}
}
}
if(pos!=-1){
for(int i=0;i<n;i++){
if(res[i]<min){
min=res[i];
pos=i;
}
}
}
return pos;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// Return the index of the catcher who gets the catch, or -1 if no one gets the catch.
int n = in.nextInt();
int x = in.nextInt();
int[] X = new int[n];
for(int X_i=0; X_i < n; X_i++){
X[X_i] = in.nextInt();
}
int[] V = new int[n];
for(int V_i=0; V_i < n; V_i++){
V[V_i] = in.nextInt();
}
int result = whoGetsTheCatch(n, x, X, V);
System.out.println(result);
in.close();
}
}