728x90
https://www.acmicpc.net/problem/1002
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine()), x1, y1, r1, x2, y2, r2, sum, diff;
double d; // distance
StringTokenizer st;
StringBuilder sb = new StringBuilder();
while (t-- > 0) {
st = new StringTokenizer(br.readLine());
x1 = Integer.parseInt(st.nextToken());
y1 = Integer.parseInt(st.nextToken());
r1 = Integer.parseInt(st.nextToken());
x2 = Integer.parseInt(st.nextToken());
y2 = Integer.parseInt(st.nextToken());
r2 = Integer.parseInt(st.nextToken());
if (x1 == x2 && y1 == y2) {
sb.append(r1 == r2 ? "-1\n" : "0\n");
continue;
}
d = Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
sum = r1 + r2;
diff = Math.abs(r1 - r2);
sb.append((sum < d || diff > d) ? "0\n"
: (sum == d || diff == d) ? "1\n"
: "2\n");
}
System.out.println(sb.toString());
}
}
반응형
'코딩 문제 풀기 ( Algorithm problem solving ) > 백준 온라인 저지 ( BOJ )' 카테고리의 다른 글
[백준(Baekjoon)][자바(java)] 1358 : 하키 / 기하 1 (0) | 2022.05.15 |
---|---|
[백준(Baekjoon)][자바(java)] 1004 : 어린 왕자 / 기하 1 (0) | 2022.05.15 |
[백준(Baekjoon)][자바(java)] 3053 : 택시 기하학 / 기하 1 (0) | 2022.05.14 |
[백준(Baekjoon)][자바(java)] 2477 : 참외밭 / 기하 1 (0) | 2022.05.13 |
[백준(Baekjoon)][자바(java)] 3034 : 앵그리 창영 / 기하 1 (0) | 2022.05.13 |