Skip to content

Commit e8e1db7

Browse files
committed
issue #36 백준 1011 Fly me to the Alpha Centauri 자바
1 parent 2ad2137 commit e8e1db7

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

‎src/backjoon/_1011.java‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package backjoon;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.util.StringTokenizer;
7+
8+
// https://www.acmicpc.net/problem/1011
9+
// Fly me to the Alpha Centauri
10+
public class _1011 {
11+
12+
public static void main(String[] args) throws IOException {
13+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
14+
//sol memory 11656 runtime 84
15+
int cnt = Integer.parseInt(br.readLine());
16+
for(int i =0; i<cnt; i++){
17+
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
18+
int x = Integer.parseInt(st.nextToken());
19+
int y = Integer.parseInt(st.nextToken());
20+
int distance = y-x;
21+
int max = (int) Math.sqrt(distance); //거리의 제곱근
22+
23+
if(max == Math.sqrt(distance)){
24+
System.out.println(max * 2 - 1);
25+
}else if(distance <= max * max + max){
26+
System.out.println(max * 2);
27+
}else {
28+
System.out.println(max * 2 + 1);
29+
}
30+
31+
}
32+
}
33+
}
34+
/*
35+
input
36+
3
37+
0 3
38+
1 5
39+
45 50
40+
41+
output
42+
3
43+
3
44+
4
45+
*/

0 commit comments

Comments
 (0)