여덟 퀸 문제: 두 판 사이의 차이

위키백과, 우리 모두의 백과사전.
내용 삭제됨 내용 추가됨
ArthurBot (토론 | 기여)
잔글 로봇: 알찬 글 ka:რვა ლაზიერის ამოცანა 를 가리키는 링크
시들해봇 (토론 | 기여)
잔글 User-controlled Bot: table syntax updated
18번째 줄: 18번째 줄:
== 해 ==
== 해 ==
8x8의 해를 나열하면 아래와 같다.
8x8의 해를 나열하면 아래와 같다.

<table>
{|
<tr>
|-
<td>
|
{{체스판|=
{{체스판|=
| tright
| tright || ||=
|
|=

8 |__|__|__|ql|__|__|__|__|=
8 |__|__|__|ql|__|__|__|__|=
7 |__|__|__|__|__|__|ql|__|=
7 |__|__|__|__|__|__|ql|__|=
36번째 줄: 34번째 줄:
|해 1
|해 1
}}
}}
|
</td>
<td>
{{체스판|=
{{체스판|=
| tright
| tright || ||=
|
|=

8 |__|__|__|__|ql|__|__|__|=
8 |__|__|__|__|ql|__|__|__|=
7 |__|ql|__|__|__|__|__|__|=
7 |__|ql|__|__|__|__|__|__|=
53번째 줄: 47번째 줄:
|해 2
|해 2
}}
}}
|
</td>
<td>
{{체스판|=
{{체스판|=
| tright
| tright || ||=
|
|=

8 |__|__|__|ql|__|__|__|__|=
8 |__|__|__|ql|__|__|__|__|=
7 |__|ql|__|__|__|__|__|__|=
7 |__|ql|__|__|__|__|__|__|=
70번째 줄: 60번째 줄:
|해 3
|해 3
}}
}}
|-
</td>
|
</tr>
<tr>
<td>
{{체스판|=
{{체스판|=
| tright
| tright || ||=
|
|=

8 |__|__|__|ql|__|__|__|__|=
8 |__|__|__|ql|__|__|__|__|=
7 |__|__|__|__|__|ql|__|__|=
7 |__|__|__|__|__|ql|__|__|=
89번째 줄: 74번째 줄:
|해 4
|해 4
}}
}}
|
</td>
<td>
{{체스판|=
{{체스판|=
| tright
| tright || ||=
|
|=

8 |__|__|ql|__|__|__|__|__|=
8 |__|__|ql|__|__|__|__|__|=
7 |__|__|__|__|__|ql|__|__|=
7 |__|__|__|__|__|ql|__|__|=
106번째 줄: 87번째 줄:
|해 5
|해 5
}}
}}
|
</td>
<td>
{{체스판|=
{{체스판|=
| tright
| tright || ||=
|
|=

8 |__|__|__|__|ql|__|__|__|=
8 |__|__|__|__|ql|__|__|__|=
7 |__|__|ql|__|__|__|__|__|=
7 |__|__|ql|__|__|__|__|__|=
123번째 줄: 100번째 줄:
|해 6
|해 6
}}
}}
|-
</td>
|
</tr>
<tr>
<td>
{{체스판|=
{{체스판|=
| tright
| tright || ||=
|
|=

8 |__|__|__|__|ql|__|__|__|=
8 |__|__|__|__|ql|__|__|__|=
7 |__|__|__|__|__|__|ql|__|=
7 |__|__|__|__|__|__|ql|__|=
142번째 줄: 114번째 줄:
|해 7
|해 7
}}
}}
|
</td>
<td>
{{체스판|=
{{체스판|=
| tright
| tright || ||=
|
|=

8 |__|__|__|ql|__|__|__|__|=
8 |__|__|__|ql|__|__|__|__|=
7 |ql|__|__|__|__|__|__|__|=
7 |ql|__|__|__|__|__|__|__|=
159번째 줄: 127번째 줄:
|해 8
|해 8
}}
}}
|
</td>
<td>
{{체스판|=
{{체스판|=
| tright
| tright || ||=
|
|=

8 |__|__|ql|__|__|__|__|__|=
8 |__|__|ql|__|__|__|__|__|=
7 |__|__|__|__|__|ql|__|__|=
7 |__|__|__|__|__|ql|__|__|=
176번째 줄: 140번째 줄:
|해 9
|해 9
}}
}}
|-
</td>
|
</tr>
<tr>
<td>
{{체스판|=
{{체스판|=
| tright
| tright || ||=
|
|=

8 |__|__|__|__|__|ql|__|__|=
8 |__|__|__|__|__|ql|__|__|=
7 |__|ql|__|__|__|__|__|__|=
7 |__|ql|__|__|__|__|__|__|=
195번째 줄: 154번째 줄:
|해 10
|해 10
}}
}}
|
</td>
<td>
{{체스판|=
{{체스판|=
| tright
| tright || ||=
|
|=

8 |__|__|__|ql|__|__|__|__|=
8 |__|__|__|ql|__|__|__|__|=
7 |__|__|__|__|__|__|ql|__|=
7 |__|__|__|__|__|__|ql|__|=
212번째 줄: 167번째 줄:
|해 11
|해 11
}}
}}
|
</td>
<td>
{{체스판|=
{{체스판|=
| tright
| tright || ||=
|
|=

8 |__|__|__|__|__|ql|__|__|=
8 |__|__|__|__|__|ql|__|__|=
7 |__|__|__|ql|__|__|__|__|=
7 |__|__|__|ql|__|__|__|__|=
229번째 줄: 180번째 줄:
|해 12
|해 12
}}
}}
|}
</td>
</tr>

</table>


== N 퀸 문제 ==
== N 퀸 문제 ==

2010년 10월 30일 (토) 01:57 판

abcdefgh
8
d8 white queen
g7 white queen
c6 white queen
h5 white queen
b4 white queen
e3 white queen
a2 white queen
f1 white queen
8
77
66
55
44
33
22
11
abcdefgh
해 중 하나.

8 퀸 문제는 8x8크기의 체스판에 을 8개 배치하는 문제이다. 1848년 막스 베첼이 처음 제안하였다. 이 문제를 일반화하면 NxN 크기의 체스판에 을 N개 배치하는 N 퀸 문제가 된다. 구성적인 해법으로 N이 2,3인경우를 제외하고 해를 찾을 수 있다.

8x8의 해를 나열하면 아래와 같다.

abcdefgh
8
f8 white queen
a6 white queen
e6 white queen
b4 white queen
d4 white queen
g3 white queen
c2 white queen
h1 white queen
8
77
66
55
44
33
22
11
abcdefgh
__
abcdefgh
8
g8 white queen
d7 white queen
f6 white queen
a4 white queen
e4 white queen
b2 white queen
h2 white queen
c1 white queen
8
77
66
55
44
33
22
11
abcdefgh
__
abcdefgh
8
f8 white queen
d7 white queen
a5 white queen
e5 white queen
h4 white queen
b2 white queen
g2 white queen
c1 white queen
8
77
66
55
44
33
22
11
abcdefgh
__
abcdefgh
8
f8 white queen
h7 white queen
b5 white queen
e5 white queen
c4 white queen
a2 white queen
g2 white queen
d1 white queen
8
77
66
55
44
33
22
11
abcdefgh
__
abcdefgh
8
e8 white queen
h7 white queen
b5 white queen
c5 white queen
f4 white queen
a2 white queen
g2 white queen
d1 white queen
8
77
66
55
44
33
22
11
abcdefgh
__
abcdefgh
8
g8 white queen
e7 white queen
b5 white queen
f5 white queen
a3 white queen
c3 white queen
h2 white queen
d1 white queen
8
77
66
55
44
33
22
11
abcdefgh
__
abcdefgh
8
g8 white queen
a6 white queen
f6 white queen
c5 white queen
e4 white queen
b2 white queen
h2 white queen
d1 white queen
8
77
66
55
44
33
22
11
abcdefgh
__
abcdefgh
8
f8 white queen
c7 white queen
g6 white queen
b4 white queen
h4 white queen
e3 white queen
a1 white queen
d1 white queen
8
77
66
55
44
33
22
11
abcdefgh
__
abcdefgh
8
e8 white queen
h7 white queen
f6 white queen
c5 white queen
b3 white queen
g3 white queen
a1 white queen
d1 white queen
8
77
66
55
44
33
22
11
abcdefgh
__
abcdefgh
8
h8 white queen
d7 white queen
a5 white queen
c5 white queen
f4 white queen
b2 white queen
g2 white queen
e1 white queen
8
77
66
55
44
33
22
11
abcdefgh
__
abcdefgh
8
f8 white queen
a6 white queen
c6 white queen
b4 white queen
g4 white queen
d3 white queen
h2 white queen
e1 white queen
8
77
66
55
44
33
22
11
abcdefgh
__
abcdefgh
8
h8 white queen
f7 white queen
a5 white queen
c5 white queen
b3 white queen
d3 white queen
g2 white queen
e1 white queen
8
77
66
55
44
33
22
11
abcdefgh
__

N 퀸 문제

아래에는n개의 퀸을 n × n 판에 나타내는 해의 수를 나타내었다. 고유한 해는(OEIS의 수열 A002562)에 일반적인 해(대칭이라도 따로 생 해는(OEIS의 수열 A000170)에 있다.

n: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 .. 24 25 26
unique: 1 0 0 1 2 1 6 12 46 92 341 1,787 9,233 45,752 .. 28,439,272,956,934 275,986,683,743,434 2,789,712,466,510,289
distinct: 1 0 0 2 10 4 40 92 352 724 2,680 14,200 73,712 365,596 .. 227,514,171,973,736 2,207,893,435,808,352 22,317,699,616,364,044

연관 문제

  • 다른 기물 사용

32개의 나이트, 14개의 비숍, 8개의 룩, 16개의 킹이 필요하다.

  • 다른 판 모양

토러스형이나 원통형 조건에 대해 생각할 수 있다. 토러스에서는 폴리아의 연구에 의해 n이 6과 서로소일때 nxn정사각형판에 n개의 퀸을 채울 수 있다.

  • 지배

최소한의 퀸을 써서 모든칸을 공격하는 것이다. 8x8에서는 5개가 필요하다.

풀이 프로그램

아래는 재귀적으로 해를 구성하는 C언어 코드이다.

#include <iostream>

using namespace std;

int board[12];
int n;
int cnt;

void path(int y) {
	int ko = 1;
	if( y == n ) {
		cnt++;
		return;
	}
	for( int i=0; i<n; i++ ) {
		ko = 1;
		for( int j=0; j<y; j++ ) {
			if( board[j] == i || abs(y-j) == abs(i-board[j]) ) {
				ko = 0;
				break;
			}
		}
		if( ko ) {
			board[y] = i;
			path(y+1);
		}
	}
}

int main() {     
	int k;
	cin >> k;

	while( k-- ) {
		cin >> n;
		cnt = 0;
		path(0);

		cout << cnt << '\n';
	}

	return 0;   
}

아래 애니메이션을 보면 재귀적으로 해를 탐색하는 과정을 알 수 있다.

틀:Link FA