AOJの0023、Circles Intersectionをc++で解きました。
中心点と半径の関係を考える問題でした。
特に詰まるところもなく、20分で解けました。
やっとc++でもある程度の処理が書けるようになって来ました。
まだまだコードが汚いと思います、、精進します。
問題文はこちら
#include <iostream> | |
#include <string> | |
#include <vector> | |
#include <cmath> | |
#define TIMES(i) while(i--) | |
#define REP(i, n) for ( int i = 0; i < n; i++ ) | |
using namespace std; | |
int main() { | |
int n; | |
cin >> n; | |
TIMES(n) { | |
// 入力 | |
double ax, ay, ar, bx, by, br; | |
cin >> ax >> ay >> ar >> bx >> by >> br; | |
// 距離を求める | |
double dis_x = abs(ax-bx), | |
dis_y = abs(ay-by), | |
dist = sqrt(dis_x * dis_x + dis_y * dis_y); | |
// cout << dis_x << " " << dis_y << " " << dist << endl; | |
// 離れている | |
if ( dist > ar + br ) { | |
cout << 0; | |
// aが内包されている | |
} else if ( dist + ar < br ) { | |
cout << -2; | |
// bが内包されている | |
} else if ( dist + br < ar ) { | |
cout << 2; | |
// 交わっている | |
} else { | |
cout << 1; | |
} | |
cout << endl; | |
} | |
return 0; | |
} |