반응형

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;
}

 

반응형

+ Recent posts