백준의 터렛 문제를 C++ 로 풀어보았다.
#include <iostream> #include <cmath> using namespace std; int main() { int caseNum = 0; int x1 = 0, y1 = 0, x2 = 0, y2 = 0; int r1 = 0, r2 = 0; cin >> caseNum; for (int i = 0; i < caseNum; i++) { cin >> x1 >> y1 >> r1 >> x2 >> y2 >> r2; double distance = sqrt(pow(abs(x1 - x2), 2) + pow(abs(y1 - y2), 2)); int maxR = r1 + r2, minR = abs(r1 - r2); if (x1 == x2 && y1 == y2 && r1 == r2) cout << -1; else if (distance == maxR || distance == minR) cout << 1; else if (minR < distance && distance < maxR) cout << 2; else cout << 0; cout << endl; } }
반응형
'Algorithm > Brute Force' 카테고리의 다른 글
CLOCKSYNC (0) | 2018.12.11 |
---|---|
TSP(Traveling Salesman Problem) (0) | 2018.12.10 |
BOARDCOVER (0) | 2018.12.08 |
PICNIC (0) | 2018.12.05 |