https://www.codetree.ai/missions/5/problems/three-lines-2?utm_source=clipboard&utm_medium=text
코드트리 | 코딩테스트 준비를 위한 알고리즘 정석
국가대표가 만든 코딩 공부의 가이드북 코딩 왕초보부터 꿈의 직장 코테 합격까지, 국가대표가 엄선한 커리큘럼으로 준비해보세요.
www.codetree.ai
완전탐색 카테고리이긴 한데,, 뭔가 생각보다 풀이를 생각하기 어려웠던 것 같다.
해설을 참고하였고, 다음에 다시 풀어볼 생각이다.
#include <iostream>
using namespace std;
int n, x[21], y[21];
int main(){
cin >> n;
for(int i=0; i<n; i++)
cin >> x[i] >> y[i];
int answer = 0;
for(int i=0; i<=10; i++){
for(int j=0; j<=10; j++){
for(int k=0; k<=10; k++){
bool s = true;
// x만 3개
for(int l = 0; l<n; l++){
if(x[l] == i || x[l] == j || x[l] == k) continue;
s = false;
}
if(s)
answer = 1;
// y가 2개 x가 1개
s = true;
for(int l = 0; l<n; l++){
if(x[l] == i || y[l] == j || y[l] == k) continue;
s = false;
}
if(s)
answer = 1;
// y가 1개 x가 2개
s = true;
for(int l = 0; l<n; l++){
if(x[l] == i || x[l] == j || y[l] == k) continue;
s = false;
}
if(s)
answer = 1;
// y가 3개
s = true;
for(int l = 0; l<n; l++){
if(y[l] == i || y[l] == j || y[l] == k) continue;
s = false;
}
if(s)
answer = 1;
}
}
}
cout << answer;
return 0;
}
'C++ > 코드트리' 카테고리의 다른 글
[코드트리] 팀으로 하는 틱택토 2 (0) | 2023.08.17 |
---|---|
[코드트리] 좌표평면 위의 균형 2 (1) | 2023.08.11 |
[코드트리] 숫자 2배 후 하나 제거하기 (1) | 2023.08.09 |
[코드트리] 야바위 (2) | 2023.08.09 |
[코드트리] 팰린드롬 수 찾기 (1) | 2023.08.09 |