Baekjoon(C++)
[C++]백준 알고리즘 1002번
DanielSoliph
2021. 8. 4. 14:40
풀이는 아래와 같다.
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
41
42
43
|
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base :: sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int T;
cin >> T;
for(int t=0; t<T; t++){
int x1,y1,x2,y2,r1,r2;
cin >> x1>> y1 >> r1 >> x2 >> y2 >> r2;
int ans = 0;
double d = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
if(x1==x2 && y1==y2){
if(r1 == r2){
ans = -1;
}else{
ans = 0;
}
}else{
if(d > r1+r2){
ans = 0;
}else if(d == r1+r2){
ans = 1;
}else{
if(d > abs(r1-r2)){
ans = 2;
}else if( d == abs(r1-r2)){
ans = 1;
}else{
ans = 0;
}
}
}
cout << ans << '\n';
}
return 0;
}
|
cs |
시행착오:
처음에는 알고리즘 자체를 짜는데에 오류가 있었는데 고치는 과정에서 계속 자잘한 실수들이 있었다.
그렇게 어려운 문제는 아니지만 구현을 할때 빼먹는 경우가 없도록 케이스 분류를 더 철저히 해야겠다.
이런 문제를 몇번이나 틀려서 다시 제출했다 허헣ㅎㅎㅎ
반응형