-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path_1011.java
More file actions
45 lines (39 loc) · 1 KB
/
_1011.java
File metadata and controls
45 lines (39 loc) · 1 KB
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
package backjoon;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
// https://www.acmicpc.net/problem/1011
// Fly me to the Alpha Centauri
public class _1011 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//sol memory 11656 runtime 84
int cnt = Integer.parseInt(br.readLine());
for(int i =0; i<cnt; i++){
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
int x = Integer.parseInt(st.nextToken());
int y = Integer.parseInt(st.nextToken());
int distance = y-x;
int max = (int) Math.sqrt(distance); //거리의 제곱근
if(max == Math.sqrt(distance)){
System.out.println(max * 2 - 1);
}else if(distance <= max * max + max){
System.out.println(max * 2);
}else {
System.out.println(max * 2 + 1);
}
}
}
}
/*
input
3
0 3
1 5
45 50
output
3
3
4
*/