🧩PS/🥉Easy
[JAVA] 백준 1002번 - 터렛
Cocoon_
2021. 10. 5. 00:14
반응형
<코드>
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for (int i = 0; i < T; i++) {
double x1 = sc.nextDouble();
double y1 = sc.nextDouble();
double r1 = sc.nextDouble();
double x2 = sc.nextDouble();
double y2 = sc.nextDouble();
double r2 = sc.nextDouble();
double d = Math.sqrt(Math.pow(x1-x2, 2)+Math.pow(y1-y2, 2));
if(r1+r2 < d) {
System.out.println(0);
} else if (r1+r2 == d) {
System.out.println(1);
} else if (r1+r2 > d) {
if(Math.abs(r1-r2) < d) {
System.out.println(2);
} else if (Math.abs(r1-r2) == d) {
if(d == 0) {
System.out.println(-1);
} else {
System.out.println(1);
}
} else if (Math.abs(r1-r2) > d) {
if(r1-r2 == 0 & d == 0) {
System.out.println(-1);
}else {
System.out.println(0);
}
}
}
}
}
}
https://www.acmicpc.net/problem/1002
1002번: 터렛
각 테스트 케이스마다 류재명이 있을 수 있는 위치의 수를 출력한다. 만약 류재명이 있을 수 있는 위치의 개수가 무한대일 경우에는 -1을 출력한다.
www.acmicpc.net
반응형