멍
Q1004 본문
어떻게 가는지 제한이 없기 때문에
출발점이나 도착점을 감싸는 원이 아닌 원들은 거쳐갈 일이 없다.
계산해서 출발점과 도착점을 포함하는 원들만 카운팅 해주면 된다.
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
29
30
31
32
33
34
35
36
37
38
|
import java.util.Scanner;
//어린왕자
public class Main {
static int[] start;
static int[] end;
static int count = 0;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int testCase = Integer.parseInt(sc.nextLine());
for(int x = 0; x < testCase; x++) {
count = 0;
start = new int[] {sc.nextInt(), sc.nextInt()};
end = new int[] {sc.nextInt(), sc.nextInt()};
sc.nextLine();
int planetCoster = Integer.parseInt(sc.nextLine());
for(int i = 0; i < planetCoster; i++) {
planetCalc(sc.nextInt(), sc.nextInt(), sc.nextInt());
sc.nextLine();
}
System.out.println(count);
}
sc.close();
//나오는길과 거리에 제한이없기때문에 다피해갈수있다고 가정할수있다.
//출발점과 도착점이 몇개의 원안에 갇혀있는지만 구하면 되는문제.
}
public static void planetCalc(int x1, int y1, int r1){
double startDistance = Math.sqrt(Math.pow(start[0]-x1, 2) + Math.pow(start[1]-y1, 2));
double endDistance = Math.sqrt(Math.pow(end[0]-x1, 2) + Math.pow(end[1]-y1, 2));
if(startDistance < r1 && endDistance < r1) {
}else if(startDistance < r1 || endDistance < r1) {
count++;
}
}
}
|
cs |
'problem solving > backjoon online judge' 카테고리의 다른 글
Q1005 ACM Craft (0) | 2019.07.08 |
---|---|
Q1003 (0) | 2019.03.07 |