https://www.acmicpc.net/problem/6987
6987번: 월드컵
월드컵 조별 최종 예선에서는 6개국으로 구성된 각 조별로 동일한 조에 소속된 국가들과 한 번씩, 각 국가별로 총 5번의 경기를 치른다. 조별리그가 끝난 후, 기자가 보내온 각 나라의 승, 무승부
www.acmicpc.net
승부가 가능한 모든 경우의 수를 정하면 6C2 = 15 이다.
그래서 모든 승부 쌍을 미리 배열에 저장해두고, 한 라운드가 진행할 때마다 승/무/패의 경우를 백트래킹으로 해결하였다.
#include <iostream>
using namespace std;
int arr[4][6][3], ans, res[6][3];
int t1[15] = { 0,0,0,0,0,1,1,1,1,2,2,2,3,3,4 };
int t2[15] = { 1,2,3,4,5,2,3,4,5,3,4,5,4,5,5 };
void go(int idx, int turn) {
if (turn == 15) {
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 3; j++) {
if (res[i][j] != arr[idx][i][j]) {
return;
}
}
}
ans = 1;
return;
}
res[t1[turn]][0]++;
res[t2[turn]][2]++;
go(idx, turn + 1);
res[t1[turn]][0]--;
res[t2[turn]][2]--;
res[t1[turn]][1]++;
res[t2[turn]][1]++;
go(idx, turn + 1);
res[t1[turn]][1]--;
res[t2[turn]][1]--;
res[t1[turn]][2]++;
res[t2[turn]][0]++;
go(idx, turn + 1);
res[t1[turn]][2]--;
res[t2[turn]][0]--;
}
int main() {
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 6; j++) {
for (int k = 0; k < 3; k++) {
cin >> arr[i][j][k];
}
}
}
for (int i = 0; i < 4; i++) {
ans = 0;
go(i, 0);
if (ans)cout << 1 << ' ';
else cout << 0 << ' ';
}
}
'ps' 카테고리의 다른 글
[백준] 1022 - 소용돌이 예쁘게 출력하기 (0) | 2022.09.04 |
---|---|
[백준] 2698 - 인접한 비트의 개수 (0) | 2022.09.03 |
[백준] 2116 - 주사위 쌓기 (0) | 2022.09.03 |
[백준] 2141 - 우체국 (0) | 2022.09.03 |
[백준] 17435 - 합성 함수와 쿼리 (0) | 2022.09.03 |
댓글