반응형
https://www.acmicpc.net/problem/1004
1004번: 어린 왕자
입력의 첫 줄에는 테스트 케이스의 개수 T가 주어진다. 그 다음 줄부터 각각의 테스트케이스에 대해 첫째 줄에 출발점 (x1, y1)과 도착점 (x2, y2)이 주어진다. 두 번째 줄에는 행성계의 개수 n이 주
www.acmicpc.net
#include <bits/stdc++.h>
using namespace std;
int stx,sty, enx,eny;
bool inAndOut(int x, int y, int r){
int startToCircleDist = (stx-x)*(stx-x) + (sty-y)*(sty-y);
int endToCircleDist = (enx-x)*(enx-x) + (eny-y)*(eny-y);
int R = r*r;
if((startToCircleDist > R && endToCircleDist < R)||(startToCircleDist < R && endToCircleDist > R)) return true;
return false;
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int T;
cin>> T;
for(int t=0;t<T; t++){
int n;
cin >> stx >> sty >> enx >> eny >> n;
int ans = 0;
for(int i=0; i<n; i++){
int x, y, r;
cin >> x >> y >> r;
if(inAndOut(x,y,r)) ans++;
}
cout << ans << '\n';
}
return 0;
}
반응형
'Algorithm > problem' 카테고리의 다른 글
백준 1167번 : 트리의 지름 - Java (0) | 2022.09.21 |
---|---|
[백준] 1914번 : 하노이 탑 - 재귀, 큰 수 (0) | 2022.09.18 |
백준 2263번 : 트리의 순회 - Java (0) | 2022.09.08 |
백준 9657번 : 돌 게임 3 - C++ (0) | 2022.09.04 |
백준 4883: 삼각 그래프 - dp (0) | 2022.09.02 |