| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
Tags
- for문
- 메이플스토리
- 루아다운로드
- c#온라인
- N Queen 문제
- c언어 버블정렬
- c언어 최대최소
- 루아
- c언어 콘서트 배열
- 비주얼 스튜디오
- 온라인 비주얼 스튜디오
- c++ 등차수열 합
- C언어 달력
- Lua language
- 2중 반복문
- LUA
- Lua 설명
- c샾 헬로우 월드
- 비주얼 스튜디오 다운로드
- c sharp hello world
- c언어 배열 programming
- N Queen Coordinates
- N Queens Problem
- c언어 콘서트 배열 2번
- 게임제작
- Lua란
- lua download
- c샾 hello world
- 유니티
- lua 다운로드
Archives
- Today
- Total
Ln Go
N Queen 좌표 출력 본문

#include<stdio.h>
#include<math.h>
int board[20], count;
int main()
{
int n, i, j;
void queen(int row, int n);
printf(" - N Queens Problem Using Backtracking -");
printf("\n\nEnter number of Queens:");
scanf_s("%d", &n);
queen(1, n);
return 0;
}
void print(int n)
{
int i, j;
printf("\n\nSolution %d:\n\n", ++count);
for (i = 1; i <= n; ++i)
{
for (j = 1; j <= n; ++j)
{
if (board[i] == j)
printf("<%d, %d> ",i,board[i]);
}
}
}
int place(int row, int column)
{
int i;
for (i = 1; i <= row - 1; ++i)
{
if (board[i] == column)
return 0;
else
if (abs(board[i] - column) == abs(i - row))
return 0;
}
return 1;
}
void queen(int row, int n)
{
int column;
for (column = 1; column <= n; ++column)
{
if (place(row, column))
{
board[row] = column;
if (row == n)
print(n);
else
queen(row + 1, n);
}
}
}'C언어' 카테고리의 다른 글
| 구조체 공용체 (0) | 2021.06.01 |
|---|---|
| c언어 최대 최소 (0) | 2021.05.26 |
| c언어 콘서트 배열 programming p292 2번 (0) | 2020.04.13 |
| c언어 콘서트 배열 programming p292 1번 (0) | 2020.04.13 |
| c언어 로또 중복x, 작은수 (0) | 2019.10.01 |
Comments