标题:简单版四皇后求讲解
只看楼主
叼着奶嘴
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2013-3-21
结帖率:66.67%
 问题点数:0 回复次数:0 
简单版四皇后求讲解
#include<stdio.h>
#include<stdlib.h>
int queen[4][4] = {0};

int main()
{
    int i = 0;
    int j = 0;
    int queenFind(int , int);

    queenFind(i,j);

    printf("1");
    getchar();
}

int queenFind(int i,int j)
{
    int k,l;
    queen[i][j] = 1;

    if(queen[0][j] + queen[1][j] + queen[2][j] + queen[3][j] == 1 && queen[i][0] + queen[i][1] + queen[i][2] + queen[i][3] == 1)
    {

        if(queenFind(i + 1,0) || queenFind(i + 1,1) || queenFind(i + 1,2) || queenFind(i + 1,3))
        {
            if(i >= 4)
            {
                for(k = 0;k < 4;k++)
                {
                    for(l = 0;l < 4;l++)
                    {
                        printf("%d ", queen[l][k]);
                    }
                    printf("\n");
                }
                getchar();
                exit(0);
            }
            return 1;
            
        }
        else
        {
            queen[i][j] = 0;
            return 0;
        }
    }
}


这个四皇后只能判断横着和竖着,怎么也改不对,求讲解,最好能完成完全版,拜谢!!
搜索更多相关主题的帖子: 皇后 include queen 
2013-03-28 14:28



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-402162-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.080825 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved