1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <algorithm>
#include <math.h>
 
using namespace std;
 
double distance(int x1, int y1, int x2, int y2) {
    return sqrt(pow(x2 - x1, 2+ pow(y2 - y1, 2));
}
 
int main() {
    int t;
    cin >> t;
 
    for (int tc = 0; tc < t; tc++) {
        double x1, y1, r1, x2, y2, r2;
        cin >> x1 >> y1 >> r1 >> x2 >> y2 >> r2;
 
        //두 점사이의 거리 구하기
        double d = distance(x1, y1, x2, y2);
 
        if (d == r1 + r2 || (max(r1, r2) - min(r1, r2) == d && d != 0)) {
            //외접, 내접
            //내접일때 d가 0이면 그냥 같은 원
            cout << "1\n";
        }
        else if (d > r1 + r2 || max(r1, r2) - min(r1, r2) > d) {
            //밖으로 떨어져 있는거, 안에 포함하고 있는 거
            cout << "0\n";
        }
        else if (max(r1, r2) - min(r1, r2) < d && d < r1 + r2) {
            cout << "2\n";
        }
        else {
            cout << "-1\n";
        }
    }
 
    return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs

 

두 원의 교점 갯수를 구하면 되는 문제

두 원의 위치 경우의 수를 잘 생각하면서 어느 경우에 몇개의 교점이 생기는지 생각해보기

 

'Baekjoon' 카테고리의 다른 글

[#11729] 하노이 탑 이동 순서  (0) 2020.03.08
[#10872] 팩토리얼  (0) 2020.03.08
[#1085] 직사각형에서 탈출  (0) 2020.03.08
[#9020] 골드바흐의 추측  (0) 2020.03.08
[#1929] 소수 구하기  (0) 2020.03.08

+ Recent posts