Notice
Recent Posts
Recent Comments
Link
«   2025/02   »
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
Tags
more
Archives
Today
Total
관리 메뉴

main

[백준-1004번/Java] 어린왕자 본문

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

'Algorithm' 카테고리의 다른 글

[백준-2564번/Java] 경비원  (0) 2022.11.13
[백준-2563번/Java] 색종이  (0) 2022.11.13
[백준-2775번/Java] 부녀회장이 될테야  (0) 2022.11.12
[백준-2108번/Java] 통계학  (0) 2022.11.12
[백준-13458번/Java] 시험 감독  (0) 2022.11.12
Comments