求数独源码

Python012

求数独源码,第1张

没试过

#include <stdio.h >

#include <stdlib.h >

int sudoku[81] // 数独题目阵列

int tempNum[81] // 上一次填数位置

int tempSp= 0 // 上一次填数位置指标

int startH[81] // 列位置的起点

int startV[81] // 行位置的起点

int startB[81] // 九宫格位置的起点

int addH[9] // 列位置的加值

int addV[9] // 行位置的加值

int addB[9] // 九宫格位置的加值

int main(int argc, char *argv[]) {

int j

if(argc>1) for(j=0j<81j++) sudoku[j]= argv[1][j]-'0'

else exit(0)

printf( "----------\n")

printSudoku(sudoku)

init() // 参数设定

tryAns() // 测试求解

printf( "----------\n")

printSudoku(sudoku)

printf( "----------\n")

}

int init() {

// 参数设定(设定这些参数之后,无论检查行、列、九宫格都方便多了)

int i

for(i=0i<81i++) {

startH[i]= i/9* 9 // 列位置的起点

startV[i]= i% 9 // 行位置的起点

startB[i]= ((i/9)/3)*27+ ((i%9)/3)*3 // 九宫格位置的起点

}

for(i=0i<9i++) {

addH[i]= i // 列位置的加值

addV[i]= i*9 // 行位置的加值

addB[i]= (i/3)*9+ (i%3) // 九宫格位置的加值

}

}

int printSudoku(int *prn) {

// 印出数独题目(阵列内容)

int i

for(i=0i<81i++) {

printf( "%2d", prn[i])

if(i%9==8) printf("\n")

}

}

int tryAns() {

// 测试求解

int sp=getNextBlank(-1) // 取得第一个空白的位置开始填入数字

do {

sudoku[sp]++ // 将本位置数字加 1

if(sudoku[sp]>9) { // 如果本位置的数字已大於 9 时则回到上一个位置继续测试

sudoku[sp]= 0

sp= pop()

} else {

if(check(sp)==0) { // 如果同行、列、九宫格都没有相同的数字,则到下一个空白处继续

push(sp) // 当然,如果发现有相同的数字时,就需把原位置的数字加 1(所以本处什麼都不做)

sp= getNextBlank(sp)

}

}

} while(sp>=0 &&sp<81)

}

int getNextBlank(int sp) {

// 取得下一个空白的位置

do {

sp++

} while(sp<81 &&sudoku[sp]>0)

return(sp)

}

int check(int sp) {

// 检查同行、列、九宫格有没有相同的数字,若有传回 1

int fg= 0

if(!fg) fg= check1(sp, startH[sp], addH) // 检查同列有没有相同的数字

if(!fg) fg= check1(sp, startV[sp], addV) // 检查同行有没有相同的数字

if(!fg) fg= check1(sp, startB[sp], addB) // 检查同九宫格有没有相同的数字

return(fg)

}

int check1(int sp, int start, int *addnum) {

// 检查指定的行、列、九宫格有没有相同的数字,若有传回 1

int fg= 0, i, sp1

for(i=0i<9i++) {

sp1= start+ addnum[i]

if(sp!=sp1 &&sudoku[sp]==sudoku[sp1]) fg++

}

return(fg)

}

int push(int sp) {

// 将指定的位置放入堆叠中

tempNum[tempSp++]= sp

}

int pop() {

// 取出堆叠中的上一个位置

if(tempSp<0) return(-1)

else return(tempNum[--tempSp])

}

参考资料:http://bbs.bc-cn.net/viewthread.php?tid=189678&page=1 算法如下,先构造一个9*9的结构体数组,表示棋盘数据0表示空白未知,结构体中每个元素

包含一个1-9的数组作为备选数字.

构建好一个棋盘之后依次对每个空白位置进行备选数字中进行删除.当前已经填写的数字就全部删除

如果只剩下一个备选数字就将该备选数字填写到棋盘数据中.该算法在AI这个函数中实现.

当无法用AI算法推出结果的时候就进行回朔法,见找到有两个备选数字的元素,选取其中一个,

继续往下填写,直到全部填写上去(结束),或者无法继续填写(某个空白位置没有备选元素).

如果无法继续填写下去就表示最初选择的那个数据是错误的,直接填写另外一个数据到棋盘上.

该算法在AdvanceAI中体现出来

如此下去就能够填写出棋盘中的所有元素.

#include <cstdio>

#include <vector>

#include <algorithm>

enum{SIZE=81}

unsigned int Data[SIZE]={//未解棋盘数据

0 , 9 , 0 , 0 , 6 , 0 , 5 , 4 , 8 ,

4 , 0 , 3 , 0 , 8 , 0 , 9 , 0 , 0 ,

8 , 6 , 5 , 4 , 7 , 9 , 1 , 2 , 3 ,

0 , 5 , 6 , 3 , 9 , 0 , 4 , 0 , 1 ,

1 , 4 , 0 , 0 , 5 , 0 , 2 , 0 , 0 ,

0 , 0 , 0 , 0 , 4 , 1 , 0 , 0 , 0 ,

0 , 0 , 0 , 8 , 2 , 0 , 6 , 1 , 0 ,

0 , 0 , 0 , 0 , 3 , 0 , 0 , 0 , 4 ,

5 , 8 , 0 , 9 , 1 , 0 , 0 , 0 , 0 }

const int temp[9] = { 1 , 2 , 3, 4, 5, 6, 7, 8, 9}

struct Item

{

int data

std::vector<int>other

Item():data(0),other(temp,temp+9){}

inline bool operator==(int x)

{

return x==data?true:false

}

inline Item&operator=(const Item&src)

{

data = src.data

other = src.other

return (*this)

}

inline Item&operator=(int x){

data = x

std::copy(temp,temp+sizeof(temp)/sizeof(temp[0]) , other.begin())

return (*this)

}

void test(size_t x ){

if( other.size() == 2 )

data = other[x]

}

inline operator int(){return data}

}

struct GroupInfo{

const int Group1,Group2,Group3

GroupInfo(int g1,int g2,int g3):Group1(g1),Group2(g2),Group3(g3){}

inline bool operator==(GroupInfo&src){

return ((Group1|Group2|Group3)&(src.Group1|src.Group2|src.Group3))?true:false

}

}

GroupInfo Group[SIZE]={

GroupInfo( 1<<1 , 1<<10 , 1<<19) ,GroupInfo( 1<<1 , 1<<11 , 1<<19) ,GroupInfo( 1<<1 , 1<<12 , 1<<19) ,GroupInfo( 1<<1 , 1<<13 , 1<<20) ,GroupInfo( 1<<1 , 1<<14 , 1<<20) ,GroupInfo( 1<<1 , 1<<15 , 1<<20) ,GroupInfo( 1<<1 , 1<<16 , 1<<21) ,GroupInfo( 1<<1 , 1<<17 , 1<<21) ,GroupInfo( 1<<1 , 1<<18 , 1<<21) ,

GroupInfo( 1<<2 , 1<<10 , 1<<19) ,GroupInfo( 1<<2 , 1<<11 , 1<<19) ,GroupInfo( 1<<2 , 1<<12 , 1<<19) ,GroupInfo( 1<<2 , 1<<13 , 1<<20) ,GroupInfo( 1<<2 , 1<<14 , 1<<20) ,GroupInfo( 1<<2 , 1<<15 , 1<<20) ,GroupInfo( 1<<2 , 1<<16 , 1<<21) ,GroupInfo( 1<<2 , 1<<17 , 1<<21) ,GroupInfo( 1<<2 , 1<<18 , 1<<21) ,

GroupInfo( 1<<3 , 1<<10 , 1<<19) ,GroupInfo( 1<<3 , 1<<11 , 1<<19) ,GroupInfo( 1<<3 , 1<<12 , 1<<19) ,GroupInfo( 1<<3 , 1<<13 , 1<<20) ,GroupInfo( 1<<3 , 1<<14 , 1<<20) ,GroupInfo( 1<<3 , 1<<15 , 1<<20) ,GroupInfo( 1<<3 , 1<<16 , 1<<21) ,GroupInfo( 1<<3 , 1<<17 , 1<<21) ,GroupInfo( 1<<3 , 1<<18 , 1<<21) ,

GroupInfo( 1<<4 , 1<<10 , 1<<22) ,GroupInfo( 1<<4 , 1<<11 , 1<<22) ,GroupInfo( 1<<4 , 1<<12 , 1<<22) ,GroupInfo( 1<<4 , 1<<13 , 1<<23) ,GroupInfo( 1<<4 , 1<<14 , 1<<23) ,GroupInfo( 1<<4 , 1<<15 , 1<<23) ,GroupInfo( 1<<4 , 1<<16 , 1<<24) ,GroupInfo( 1<<4 , 1<<17 , 1<<24) ,GroupInfo( 1<<4 , 1<<18 , 1<<24) ,

GroupInfo( 1<<5 , 1<<10 , 1<<22) ,GroupInfo( 1<<5 , 1<<11 , 1<<22) ,GroupInfo( 1<<5 , 1<<12 , 1<<22) ,GroupInfo( 1<<5 , 1<<13 , 1<<23) ,GroupInfo( 1<<5 , 1<<14 , 1<<23) ,GroupInfo( 1<<5 , 1<<15 , 1<<23) ,GroupInfo( 1<<5 , 1<<16 , 1<<24) ,GroupInfo( 1<<5 , 1<<17 , 1<<24) ,GroupInfo( 1<<5 , 1<<18 , 1<<24) ,

GroupInfo( 1<<6 , 1<<10 , 1<<22) ,GroupInfo( 1<<6 , 1<<11 , 1<<22) ,GroupInfo( 1<<6 , 1<<12 , 1<<22) ,GroupInfo( 1<<6 , 1<<13 , 1<<23) ,GroupInfo( 1<<6 , 1<<14 , 1<<23) ,GroupInfo( 1<<6 , 1<<15 , 1<<23) ,GroupInfo( 1<<6 , 1<<16 , 1<<24) ,GroupInfo( 1<<6 , 1<<17 , 1<<24) ,GroupInfo( 1<<6 , 1<<18 , 1<<24) ,

GroupInfo( 1<<7 , 1<<10 , 1<<25) ,GroupInfo( 1<<7 , 1<<11 , 1<<25) ,GroupInfo( 1<<7 , 1<<12 , 1<<25) ,GroupInfo( 1<<7 , 1<<13 , 1<<26) ,GroupInfo( 1<<7 , 1<<14 , 1<<26) ,GroupInfo( 1<<7 , 1<<15 , 1<<26) ,GroupInfo( 1<<7 , 1<<16 , 1<<27) ,GroupInfo( 1<<7 , 1<<17 , 1<<27) ,GroupInfo( 1<<7 , 1<<18 , 1<<27) ,

GroupInfo( 1<<8 , 1<<10 , 1<<25) ,GroupInfo( 1<<8 , 1<<11 , 1<<25) ,GroupInfo( 1<<8 , 1<<12 , 1<<25) ,GroupInfo( 1<<8 , 1<<13 , 1<<26) ,GroupInfo( 1<<8 , 1<<14 , 1<<26) ,GroupInfo( 1<<8 , 1<<15 , 1<<26) ,GroupInfo( 1<<8 , 1<<16 , 1<<27) ,GroupInfo( 1<<8 , 1<<17 , 1<<27) ,GroupInfo( 1<<8 , 1<<18 , 1<<27) ,

GroupInfo( 1<<9 , 1<<10 , 1<<25) ,GroupInfo( 1<<9 , 1<<11 , 1<<25) ,GroupInfo( 1<<9 , 1<<12 , 1<<25) ,GroupInfo( 1<<9 , 1<<13 , 1<<26) ,GroupInfo( 1<<9 , 1<<14 , 1<<26) ,GroupInfo( 1<<9 , 1<<15 , 1<<26) ,GroupInfo( 1<<9 , 1<<16 , 1<<27) ,GroupInfo( 1<<9 , 1<<17 , 1<<27) ,GroupInfo( 1<<9 , 1<<18 , 1<<27)

}

bool AI(std::vector<Item>&game)

{

bool bMoveflag = false

for(size_t x = 0 x <game.size() ++x ){

if( 0 != game[x].data ){//依次检查每个位置

game[x].other.resize(0)

continue

}

//当前位置没有数字

std::vector<int>vTemp

for(int i = 0 i <81 ++i )

if( Group[x]==Group[i] )

vTemp.push_back ( game[i].data )

vTemp.erase( std::remove(vTemp.begin(),vTemp.end() , 0 ) , vTemp.end() )

//移除同组已经出现的数字

for(std::vector<int>::iterator Iter = vTemp.begin() Iter !=vTemp.end() ++ Iter )

std::replace(game[x].other.begin() , game[x].other.end() , (*Iter) , 0 )

game[x].other.erase( std::remove(game[x].other.begin(),game[x].other.end() , 0 ) ,game[x].other.end() )

if( ( 1 == game[x].other.size())&&( 0 != game[x].other[0] ) ){

game[x].data = game[x].other[0]

bMoveflag = true

}

}

return bMoveflag

}

struct OtherIs2Opt{

bool operator()(Item&item)

{return ( item.other.size()==2)?true:false}

}

struct testBackOpt

{

bool bBack

testBackOpt():bBack(false){}

void operator()(Item&item)

{

if( ( item.data==0)&&(item.other.size()==0) )

bBack = true

}

}

bool AdvanceAI(std::vector<Item>&game)

{

std::vector<Item>Back = game

std::vector<Item>::iterator iItem = std::find_if( Back.begin() , Back.end() , OtherIs2Opt() )

if( iItem != Back.end() ){

for(size_t i = 0 i <(*iItem).other.size() ++i ){

(*iItem).test( i )

for( AI( Back ) )

if( std::for_each( Back.begin() , Back.end() , testBackOpt() ).bBack ){//是否结束回滚

Back = game

iItem = std::find_if( Back.begin() , Back.end() , OtherIs2Opt() )

continue

}

if( std::count( Back.begin() , Back.end() , 0 ) ){//判断是否结束

if( AdvanceAI( Back ) ){//没有结束,继续下一步递归

game = Back

return true

}

Back = game

iItem = std::find_if( Back.begin() , Back.end() , OtherIs2Opt() )

continue

}else{//back为结果

game = Back

return true

}

}

}

return false

}

int main(int argc, char* argv[])

{//初始化棋盘

std::vector<Item>game(SIZE)

std::copy(Data,Data+SIZE , game.begin() )

for( AI( game ) )

if( std::count( game.begin() , game.end() , 0 ) ){

if( !AdvanceAI( game ) )

printf("没解出来 ")

}

for(int x = 0 x <81 ++x ){

printf(" %d",game[x].data )

if( 0 == (x +1)% 9 )

printf(" ")

}

return 0算法如下,先构造一个9*9的结构体数组,表示棋盘数据0表示空白未知,结构体中每个元素

包含一个1-9的数组作为备选数字.

构建好一个棋盘之后依次对每个空白位置进行备选数字中进行删除.当前已经填写的数字就全部删除

如果只剩下一个备选数字就将该备选数字填写到棋盘数据中.该算法在AI这个函数中实现.

当无法用AI算法推出结果的时候就进行回朔法,见找到有两个备选数字的元素,选取其中一个,

继续往下填写,直到全部填写上去(结束),或者无法继续填写(某个空白位置没有备选元素).

如果无法继续填写下去就表示最初选择的那个数据是错误的,直接填写另外一个数据到棋盘上.

该算法在AdvanceAI中体现出来

如此下去就能够填写出棋盘中的所有元素.

#include <cstdio>

#include <vector>

#include <algorithm>

enum{SIZE=81}

unsigned int Data[SIZE]={//未解棋盘数据

0 , 9 , 0 , 0 , 6 , 0 , 5 , 4 , 8 ,

4 , 0 , 3 , 0 , 8 , 0 , 9 , 0 , 0 ,

8 , 6 , 5 , 4 , 7 , 9 , 1 , 2 , 3 ,

0 , 5 , 6 , 3 , 9 , 0 , 4 , 0 , 1 ,

1 , 4 , 0 , 0 , 5 , 0 , 2 , 0 , 0 ,

0 , 0 , 0 , 0 , 4 , 1 , 0 , 0 , 0 ,

0 , 0 , 0 , 8 , 2 , 0 , 6 , 1 , 0 ,

0 , 0 , 0 , 0 , 3 , 0 , 0 , 0 , 4 ,

5 , 8 , 0 , 9 , 1 , 0 , 0 , 0 , 0 }

const int temp[9] = { 1 , 2 , 3, 4, 5, 6, 7, 8, 9}

struct Item

{

int data

std::vector<int>other

Item():data(0),other(temp,temp+9){}

inline bool operator==(int x)

{

return x==data?true:false

}

inline Item&operator=(const Item&src)

{

data = src.data

other = src.other

return (*this)

}

inline Item&operator=(int x){

data = x

std::copy(temp,temp+sizeof(temp)/sizeof(temp[0]) , other.begin())

return (*this)

}

void test(size_t x ){

if( other.size() == 2 )

data = other[x]

}

inline operator int(){return data}

}

struct GroupInfo{

const int Group1,Group2,Group3

GroupInfo(int g1,int g2,int g3):Group1(g1),Group2(g2),Group3(g3){}

inline bool operator==(GroupInfo&src){

return ((Group1|Group2|Group3)&(src.Group1|src.Group2|src.Group3))?true:false

}

}

GroupInfo Group[SIZE]={

GroupInfo( 1<<1 , 1<<10 , 1<<19) ,GroupInfo( 1<<1 , 1<<11 , 1<<19) ,GroupInfo( 1<<1 , 1<<12 , 1<<19) ,GroupInfo( 1<<1 , 1<<13 , 1<<20) ,GroupInfo( 1<<1 , 1<<14 , 1<<20) ,GroupInfo( 1<<1 , 1<<15 , 1<<20) ,GroupInfo( 1<<1 , 1<<16 , 1<<21) ,GroupInfo( 1<<1 , 1<<17 , 1<<21) ,GroupInfo( 1<<1 , 1<<18 , 1<<21) ,

GroupInfo( 1<<2 , 1<<10 , 1<<19) ,GroupInfo( 1<<2 , 1<<11 , 1<<19) ,GroupInfo( 1<<2 , 1<<12 , 1<<19) ,GroupInfo( 1<<2 , 1<<13 , 1<<20) ,GroupInfo( 1<<2 , 1<<14 , 1<<20) ,GroupInfo( 1<<2 , 1<<15 , 1<<20) ,GroupInfo( 1<<2 , 1<<16 , 1<<21) ,GroupInfo( 1<<2 , 1<<17 , 1<<21) ,GroupInfo( 1<<2 , 1<<18 , 1<<21) ,

GroupInfo( 1<<3 , 1<<10 , 1<<19) ,GroupInfo( 1<<3 , 1<<11 , 1<<19) ,GroupInfo( 1<<3 , 1<<12 , 1<<19) ,GroupInfo( 1<<3 , 1<<13 , 1<<20) ,GroupInfo( 1<<3 , 1<<14 , 1<<20) ,GroupInfo( 1<<3 , 1<<15 , 1<<20) ,GroupInfo( 1<<3 , 1<<16 , 1<<21) ,GroupInfo( 1<<3 , 1<<17 , 1<<21) ,GroupInfo( 1<<3 , 1<<18 , 1<<21) ,

GroupInfo( 1<<4 , 1<<10 , 1<<22) ,GroupInfo( 1<<4 , 1<<11 , 1<<22) ,GroupInfo( 1<<4 , 1<<12 , 1<<22) ,GroupInfo( 1<<4 , 1<<13 , 1<<23) ,GroupInfo( 1<<4 , 1<<14 , 1<<23) ,GroupInfo( 1<<4 , 1<<15 , 1<<23) ,GroupInfo( 1<<4 , 1<<16 , 1<<24) ,GroupInfo( 1<<4 , 1<<17 , 1<<24) ,GroupInfo( 1<<4 , 1<<18 , 1<<24) ,

GroupInfo( 1<<5 , 1<<10 , 1<<22) ,GroupInfo( 1<<5 , 1<<11 , 1<<22) ,GroupInfo( 1<<5 , 1<<12 , 1<<22) ,GroupInfo( 1<<5 , 1<<13 , 1<<23) ,GroupInfo( 1<<5 , 1<<14 , 1<<23) ,GroupInfo( 1<<5 , 1<<15 , 1<<23) ,GroupInfo( 1<<5 , 1<<16 , 1<<24) ,GroupInfo( 1<<5 , 1<<17 , 1<<24) ,GroupInfo( 1<<5 , 1<<18 , 1<<24) ,

GroupInfo( 1<<6 , 1<<10 , 1<<22) ,GroupInfo( 1<<6 , 1<<11 , 1<<22) ,GroupInfo( 1<<6 , 1<<12 , 1<<22) ,GroupInfo( 1<<6 , 1<<13 , 1<<23) ,GroupInfo( 1<<6 , 1<<14 , 1<<23) ,GroupInfo( 1<<6 , 1<<15 , 1<<23) ,GroupInfo( 1<<6 , 1<<16 , 1<<24) ,GroupInfo( 1<<6 , 1<<17 , 1<<24) ,GroupInfo( 1<<6 , 1<<18 , 1<<24) ,

GroupInfo( 1<<7 , 1<<10 , 1<<25) ,GroupInfo( 1<<7 , 1<<11 , 1<<25) ,GroupInfo( 1<<7 , 1<<12 , 1<<25) ,GroupInfo( 1<<7 , 1<<13 , 1<<26) ,GroupInfo( 1<<7 , 1<<14 , 1<<26) ,GroupInfo( 1<<7 , 1<<15 , 1<<26) ,GroupInfo( 1<<7 , 1<<16 , 1<<27) ,GroupInfo( 1<<7 , 1<<17 , 1<<27) ,GroupInfo( 1<<7 , 1<<18 , 1<<27) ,

GroupInfo( 1<<8 , 1<<10 , 1<<25) ,GroupInfo( 1<<8 , 1<<11 , 1<<25) ,GroupInfo( 1<<8 , 1<<12 , 1<<25) ,GroupInfo( 1<<8 , 1<<13 , 1<<26) ,GroupInfo( 1<<8 , 1<<14 , 1<<26) ,GroupInfo( 1<<8 , 1<<15 , 1<<26) ,GroupInfo( 1<<8 , 1<<16 , 1<<27) ,GroupInfo( 1<<8 , 1<<17 , 1<<27) ,GroupInfo( 1<<8 , 1<<18 , 1<<27) ,

GroupInfo( 1<<9 , 1<<10 , 1<<25) ,GroupInfo( 1<<9 , 1<<11 , 1<<25) ,GroupInfo( 1<<9 , 1<<12 , 1<<25) ,GroupInfo( 1<<9 , 1<<13 , 1<<26) ,GroupInfo( 1<<9 , 1<<14 , 1<<26) ,GroupInfo( 1<<9 , 1<<15 , 1<<26) ,GroupInfo( 1<<9 , 1<<16 , 1<<27) ,GroupInfo( 1<<9 , 1<<17 , 1<<27) ,GroupInfo( 1<<9 , 1<<18 , 1<<27)

}

bool AI(std::vector<Item>&game)

{

bool bMoveflag = false

for(size_t x = 0 x <game.size() ++x ){

if( 0 != game[x].data ){//依次检查每个位置

game[x].other.resize(0)

continue

}

//当前位置没有数字

std::vector<int>vTemp

for(int i = 0 i <81 ++i )

if( Group[x]==Group[i] )

vTemp.push_back ( game[i].data )

vTemp.erase( std::remove(vTemp.begin(),vTemp.end() , 0 ) , vTemp.end() )

//移除同组已经出现的数字

for(std::vector<int>::iterator Iter = vTemp.begin() Iter !=vTemp.end() ++ Iter )

std::replace(game[x].other.begin() , game[x].other.end() , (*Iter) , 0 )

game[x].other.erase( std::remove(game[x].other.begin(),game[x].other.end() , 0 ) ,game[x].other.end() )

if( ( 1 == game[x].other.size())&&( 0 != game[x].other[0] ) ){

game[x].data = game[x].other[0]

bMoveflag = true

}

}

return bMoveflag

}

struct OtherIs2Opt{

bool operator()(Item&item)

{return ( item.other.size()==2)?true:false}

}

struct testBackOpt

{

bool bBack

testBackOpt():bBack(false){}

void operator()(Item&item)

{

if( ( item.data==0)&&(item.other.size()==0) )

bBack = true

}

}

bool AdvanceAI(std::vector<Item>&game)

{

std::vector<Item>Back = game

std::vector<Item>::iterator iItem = std::find_if( Back.begin() , Back.end() , OtherIs2Opt() )

if( iItem != Back.end() ){

for(size_t i = 0 i <(*iItem).other.size() ++i ){

(*iItem).test( i )

for( AI( Back ) )

if( std::for_each( Back.begin() , Back.end() , testBackOpt() ).bBack ){//是否结束回滚

Back = game

iItem = std::find_if( Back.begin() , Back.end() , OtherIs2Opt() )

continue

}

if( std::count( Back.begin() , Back.end() , 0 ) ){//判断是否结束

if( AdvanceAI( Back ) ){//没有结束,继续下一步递归

game = Back

return true

}

Back = game

iItem = std::find_if( Back.begin() , Back.end() , OtherIs2Opt() )

continue

}else{//back为结果

game = Back

return true

}

}

}

return false

}

int main(int argc, char* argv[])

{//初始化棋盘

std::vector<Item>game(SIZE)

std::copy(Data,Data+SIZE , game.begin() )

for( AI( game ) )

if( std::count( game.begin() , game.end() , 0 ) ){

if( !AdvanceAI( game ) )

printf("没解出来 ")

}

for(int x = 0 x <81 ++x ){

printf(" %d",game[x].data )

if( 0 == (x +1)% 9 )

printf(" ")

}

return 0

1.Docker项目

网址为 https://github.com/docker/docker 。

介绍:Docker是一种操作系统层面的虚拟化技术,可以在操作系统和应用程序之间进行隔离,也可以称之为容器。Docker可以在一台物理服务器上快速运行一个或多个实例。例如,启动一个Cent OS操作系统,并在其内部命令行执行指令后结束,整个过程就像自己在操作系统一样高效。

2.golang项目

网址为 https://github.com/golang/go 。

介绍:Go语言的早期源码使用C语言和汇编语言写成。从Go 1.5版本自举后,完全使用Go语言自身进行编写。Go语言的源码对了解Go语言的底层调度有极大的参考意义,建议希望对Go语言有深入了解的读者读一读。

3.Kubernetes项目

网址为 https://github.com/kubernetes/kubernetes 。

介绍:Google公司开发的构建于Docker之上的容器调度服务,用户可以通过Kubernetes集群进行云端容器集群管理。

4.etcd项目

网址为 https://github.com/coreos/etcd 。

介绍:一款分布式、可靠的KV存储系统,可以快速进行云配置。

5.beego项目

网址为 https://github.com/astaxie/beego 。

介绍:beego是一个类似Python的Tornado框架,采用了RESTFul的设计思路,使用Go语言编写的一个极轻量级、高可伸缩性和高性能的Web应用框架。

6.martini项目

网址为 https://github.com/go-martini/martini 。

介绍:一款快速构建模块化的Web应用的Web框架。

7.codis项目

网址为 https://github.com/Codis Labs/codis。

介绍:国产的优秀分布式Redis解决方案。

8.delve项目

网址为 https://github.com/derekparker/delve 。

介绍:Go语言强大的调试器,被很多集成环境和编辑器整合。