※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 26509번 문제인 Triangle이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/26509
26509번: Triangle
The first line of input contains a positive integer n, indicating the number of problem sets. Each problem set consists of two lines. The first line contains three space-separated positive integers, indicating the desired side lengths of the first triangle
www.acmicpc.net
두 삼각형 두개를 이어붙여 직사각형을 만들 수 있는 경우는 두 삼각형이 합동인 직각삼각형인 경우뿐임을 관찰하자.
이를 이용해, 두 삼각형의 변을 각각 크기순으로 정렬해 둘이 같은 배열인지를 확인하고 해당 배열의 세 변이 직각삼각형을 구성하는지를 확인하는 것으로 문제를 해결하자.
아래는 제출한 소스코드이다.
#include <iostream>
#include <algorithm>
using namespace std;
int T;
int arr1[3], arr2[3];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> T;
while (T--) {
cin >> arr1[0] >> arr1[1] >> arr1[2] >> arr2[0] >> arr2[1] >> arr2[2];
sort(arr1, arr1 + 3);
sort(arr2, arr2 + 3);
if (arr1[0] == arr2[0] && arr1[1] == arr2[1] && arr1[2] == arr2[2] && arr1[0] * arr1[0] + arr1[1] * arr1[1] == arr1[2] * arr1[2]) cout << "YES\n";
else cout << "NO\n";
}
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 26510 // C++] V for Vendetta (0) | 2022.12.21 |
---|---|
[BOJ 22421 // C++] Koto Municipal Subway (0) | 2022.12.21 |
[BOJ 5356 // C++] Triangles (0) | 2022.12.21 |
[BOJ 26534 // C++] Goats (0) | 2022.12.21 |
[BOJ 26548 // C++] Quadratics (0) | 2022.12.21 |