-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmountainbiking.java
31 lines (29 loc) · 1.17 KB
/
mountainbiking.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
import java.io.*;
import java.util.*;
public class mountainbiking {
public static void main(String[] args) throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
StringTokenizer st = new StringTokenizer(in.readLine());
int n = Integer.parseInt(st.nextToken());
double g = Double.parseDouble(st.nextToken());
double[] dist = new double[n];
double[] theta = new double[n];
for(int i = 0; i < n; i++) {
st = new StringTokenizer(in.readLine());
double d = Double.parseDouble(st.nextToken());
double t = Double.parseDouble(st.nextToken());
dist[i] = d;
theta[i] = t;
}
double v = 0;
ArrayList<Double> output = new ArrayList<Double>();
for(int i = n - 1; i >= 0; i--) {
v = Math.sqrt(v * v + 2 * g * Math.cos(Math.toRadians(theta[i])) * dist[i]);
output.add(v);
}
for(int i = output.size() - 1; i >= 0; i--)
out.println(output.get(i));
out.close();
}
}