728x90
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
double calculate_distance(int ax, int ay, int bx, int by) {
return sqrt(pow((ax - bx), 2) + pow((ay - by), 2));
}
int main(int argc, char* argv[]) {
int num_test_case = 0;
double distance_of_centers = 0.0;
int sum_of_radius = 0, sub_of_radius = 0;
scanf("%d", &num_test_case);
int* cases = (int*)malloc(sizeof(int) * 6 * num_test_case);
for (int i = 0; i < num_test_case; i++) {
scanf("%d %d %d %d %d %d", &cases[6 * i], &cases[6 * i + 1], &cases[6 * i + 2], &cases[6 * i + 3], &cases[6 * i + 4], &cases[6 * i + 5]);
if (cases[6 * i] < -10000 || cases[6 * i] > 10000 || cases[6 * i + 1] < -10000 || cases[6 * i + 1] > 10000 || cases[6 * i + 2] < 1 || cases[6 * i + 2] > 10000 || cases[6 * i + 3] < -10000 || cases[6 * i + 3] > 10000 || cases[6 * i + 4] < -10000 || cases[6 * i + 4] > 10000 || cases[6 * i + 5] < 1 || cases[6 * i + 5] > 10000)
{
printf("Error");
return -1;
}
}
for (int i = 0; i < num_test_case; i++) {
distance_of_centers = calculate_distance(cases[6 * i], cases[6 * i + 1], cases[6 * i + 3], cases[6 * i + 4]);
sum_of_radius = cases[6 * i + 2] + cases[6 * i + 5];
sub_of_radius = cases[6 * i + 2] > cases[6 * i + 5] ? cases[6 * i + 2] - cases[6 * i + 5] : cases[6 * i + 5] - cases[6 * i + 2];
if (distance_of_centers > sum_of_radius) //case 1
printf("0\n");
else if ((distance_of_centers == sum_of_radius || distance_of_centers == sub_of_radius) && distance_of_centers != 0)//case 2,6
printf("1\n");
else if (distance_of_centers > sub_of_radius && distance_of_centers < sum_of_radius)//case 3
printf("2\n");
else if (distance_of_centers < sub_of_radius)//case 4
printf("0\n");
else if (distance_of_centers == 0 && sub_of_radius == 0)//case 5
printf("-1\n");
}
}
728x90
'C, C++ > 백준' 카테고리의 다른 글
[백준] 2231 분해합 (0) | 2024.02.22 |
---|---|
[백준] 1546 평균 (1) | 2024.02.15 |
[백준] 1436 영화감독 숌 (1) | 2024.02.10 |
[백준] 1259 팬린드롬수 (1) | 2024.02.10 |
[백준] 10828 (0) | 2023.11.20 |