克里斯保罗 发表于 2019-7-15 23:04:51

朕想知道

夜雨闻铃 发表于 2019-7-17 21:12:00

朕想知道

echohah 发表于 2019-7-18 21:47:15

朕想知道

乔宽 发表于 2019-7-19 16:49:13

朕想知道

ShaoDaria 发表于 2019-7-22 21:45:42

朕想知道

ShaoDaria 发表于 2019-7-22 21:47:41

朕想知道

陌曦衣 发表于 2019-7-23 16:09:40

让我瞅瞅

AINR 发表于 2019-7-30 13:11:58

1

huoxr 发表于 2019-8-1 09:37:17

想看

月无涯 发表于 2019-8-1 17:30:32

kk

飘逸的光头 发表于 2019-8-1 18:54:26

看答案

joker__ 发表于 2019-8-3 23:00:43


朕想知道

DT_Nelson 发表于 2019-8-10 14:17:54

I want to know.

DT_Nelson 发表于 2019-8-10 14:34:25

#include <stdio.h>

#define S 8

int chbrd;
int count = 0;

void init(void){
        int i, j;
        for(i = 0; i < S; i++){
                for(j = 0; j < S; j++){
                        chbrd = 0;
                }
        }
}

void disp(void){
        int i, j;
        for(i = 0; i < S; i++){
                for(j = 0; j < S; j++){
                        printf("%d ", chbrd);
                }
                putchar('\n');
        }
        putchar('\n');
}

_Bool issafe(int x, int y){
        int i, j;
        for(i = 0; i < S; i++){
                if(chbrd == 1){
                        return 0;
                }
        }
        for(i = 0; i < S; i++){
                if(chbrd == 1){
                        return 0;
                }
        }

        for(i = x, j = y; i>=0 && j<S; i--, j++){
                if(chbrd == 1){
                        return 0;
                }
        }
        for(i = x, j = y; i>=0 && j>=0; i--, j--){
                if(chbrd == 1){
                        return 0;
                }
        }
        return 1;
}

void next_queen(int x){
        int i, j;
        if(x == S){
                count++;
                disp();
                return;
        }
        for(i = 0; i < S; i++){
                if(!issafe(x, i)){
                        continue;
                }
                chbrd = 1;
                next_queen(x+1);
                chbrd = 0;
        }
}

int main(void){
        init();
        next_queen(0);
        printf("There are %d solutions in total.\n", count);
        return 0;
}

juhugufudu 发表于 2019-8-12 20:06:11

aa

清尘yt 发表于 2019-8-15 15:08:17

打卡学习

可爱的失踪人口 发表于 2019-8-15 16:59:02

朕想知道

gzq07 发表于 2019-8-16 10:42:29

朕想知道

Juejiu66 发表于 2019-8-16 12:23:08

xx

分析的化身 发表于 2019-8-16 18:01:01

朕想知道
页: 1 2 3 4 5 6 7 [8] 9 10 11 12 13 14 15 16 17
查看完整版本: 通用解题思想:回溯法(附八皇后问题解析)