Algorithm
[백준-1004번/Java] 어린왕자
1984
2022. 11. 12. 23:03
* 출발점/도착점 중 하나만 원 내부에 있는 경우만 count를 센다.
* 하나의 원 안에 출발점과 도착점이 모두있는 경우에는, 원을 지나지 않고 도착할 수 있으므로 count를 세지 않는다.
* 기하학
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
Scanner scan = new Scanner(System.in);
int T = scan.nextInt();
for (int i = 0; i < T; i++) {
int x1 = scan.nextInt();
int y1 = scan.nextInt();
int x2 = scan.nextInt();
int y2 = scan.nextInt();
int count = 0;
int N = scan.nextInt();
for (int j = 0; j < N; j++) {
int cx = scan.nextInt();
int cy = scan.nextInt();
int r = scan.nextInt();
if (Math.pow(r, 2) >= Math.pow(cx - x1, 2) + Math.pow(cy - y1, 2)
&& Math.pow(r, 2) >= Math.pow(cx - x2, 2) + Math.pow(cy - y2, 2)) {
} else if (Math.pow(r, 2) >= Math.pow(cx - x1, 2) + Math.pow(cy - y1, 2)
|| Math.pow(r, 2) >= Math.pow(cx - x2, 2) + Math.pow(cy - y2, 2)) {
count++;
}
}
System.out.println(count);
}
scan.close();
}
}
728x90