문제 링크
https://www.acmicpc.net/problem/1004
풀이
const input = require("fs").readFileSync("dev/stdin").toString().trim().split(/\s/);
let idx = 0;
const answer = [];
const T = +input[idx++];
for (let i=0; i<T; i++) {
let count = 0;
const [x1, y1, x2, y2] = input.slice(idx, idx+4).map(v => +v);
idx += 4;
const n = +input[idx++];
for (let j=0; j<n; j++) {
const [cx, cy, r] = input.slice(idx, idx+3).map(v => +v);
idx += 3;
if ((x1-cx)**2 + (y1-cy)**2 < r**2) count++;
if ((x2-cx)**2 + (y2-cy)**2 < r**2) count++;
if ((x1-cx)**2 + (y1-cy)**2 < r**2 && (x2-cx)**2 + (y2-cy)**2 < r**2) count -= 2;
}
answer.push(count);
}
console.log(answer.join("\n"));
출발점 또는 도착점이 특정 원 안에 있는지 여부를 확인하여 원 안에 있다면 count를 증가시킨다. 그러나, 출발점과 도착점 모두 하나의 원 안에 있다면 해당 행성계에 진입 또는 이탈이 일어나지 않기 때문에 증가시켰던 count를 다시 뺀다.
'연습장 > 백준(BOJ) 문제풀이' 카테고리의 다른 글
[백준 2448] 별 찍기 - 11 with Python (0) | 2021.07.06 |
---|---|
[백준 2630] 색종이 만들기 with Node.js (0) | 2021.06.04 |
[백준 11053] 가장 긴 증가하는 부분 수열 with Python (0) | 2021.05.29 |
[백준 10974] 모든 순열 with Node.js (0) | 2021.05.25 |
[백준 1012] 유기농 배추 with Python (0) | 2021.05.25 |