
const fs = require('fs');
const path = process.platform === 'linux' ? '/dev/stdin' : 'input.txt';
const [T, ...inputs] = fs.readFileSync(path).toString().trim().split('\n');
let front = 0;
for (let _ = 0; _ < +T; _++) {
const [x1, y1, x2, y2] = inputs[front++].split(' ').map(Number);
const n = +inputs[front++];
let ans = 0;
for (let i = 0; i < n; i++) {
const [cx, cy, r] = inputs[front++].split(' ').map(Number);
const isIncludeStart = (x1 - cx) ** 2 + (y1 - cy) ** 2 < r ** 2;
const isIncludeEnd = (x2 - cx) ** 2 + (y2 - cy) ** 2 < r ** 2;
// 시작 좌표가 몇개 안의 행성계 안에 갇혀있는지
// 끝 좌표가 몇개 안의 행성계 안에 갇혀있는지
if (isIncludeStart && isIncludeEnd) continue;
else if (isIncludeStart || isIncludeEnd) ans += 1;
}
console.log(ans);
}
⏰ 소요한 시간 : -
간단한 수학문제다.
헷갈릴 수 있지만 조금 고민해보면 시작점과 끝점을 감싸고 있는 원의 개수를 세어주면 된다.
원이 점을 감싸는지는 점과 원의 중점거리가 반지름보다 작으면 된다.
이 때 시작점과 끝점이 모두 원에 감싸져있다면 세어줄 필요 없다는 것을 체크 해줘야 한다.