본문 바로가기

백준

1002 터렛

ㅋㅋㅋㅋㅋㅋㅠ 미치겠다 저기 사람 있었구나 저걸 누가 아냐고ㅋㅋㅋㅋㅋㅋㅋ 터렛 안에 사람 있어요 (???????) 아 자꾸 피식하게 됨

 

 

문제 파악해보니 두 원이 주어졌을 때 원의 교점을 구하는 문제였다. 허어어... 퇴근하고 운동하고 플젝하고 푸는거라 개피곤하다... 내일 아침에 풀겠음

 

--- 

아침에 풀었음!

처음에 착각해서 무한인 경우가 이런 건 줄 알았다. 그런데 예시가 0이어서 고민하다가 두 개가 똑같은 원인 경우 무한이라는 걸 알았다. 

 

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <math.h>
#define xx first
#define yy second
#define all(x) (x).begin(), (x).end()
#pragma warning(disable:4996)

using namespace std;
using i64 = long long;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;

void solve() {
    double x1, y1, r1, x2, y2, r2;
    scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &r1, &x2, &y2, &r2);
    
    if (x1 == x2 && y1 == y2 && r1 == r2) {
        printf("-1\n");
        return;
    }
    
    double d = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
    
    int res = 0;
    if (d == r1 + r2)
        res = 1;
    else if (d < r1 + r2) {
        if (abs(r2 - r1) == d)
            res = 1;
        else if (abs(r2 - r1) > d)
            res = 0;
        else
            res = 2;
    }
    else {
        res = 0;
    }
        
    printf("%d\n", res);
}

int main() {
    int n;
    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
        solve();
    }

    return 0;
}

'백준' 카테고리의 다른 글

14881 물통 문제  (2) 2021.08.07
1676 팩토리얼 0의 개수  (0) 2021.08.07
1015 수열 정렬  (0) 2021.08.04
12933 오리  (0) 2021.08.03
1018 체스판 다시 칠하기  (0) 2021.08.01