| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 508 人关注过本帖
标题:[求助]
只看楼主 加入收藏
英雄
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2005-12-7
收藏
 问题点数:0 回复次数:0 
[求助]

各位高手好:
小弟有一八皇后问题解法!望大家指教!

谢谢!
#include "stdafx.h"
#include"iostream.h"
#include"math.h"

void putIn(int);
int panDuan(int);

int columnRecord[8] = {0},n=0,map[8][8] = {0};

int main(int argc, char* argv[])
{
putIn(0);
cout<<"total is:"<<n<<endl;

return 0;
}
void putIn(int row)
{
int column,i,j;

if(row>7)
{
for(i=0;i<8;i++)
{
for(j=0;j<8;j++)
if(map[i][j]==1)
cout<<"1 ";
else
cout<<"0 ";
cout<<endl;

}
n++;
cout<<"//////////////////////////////////////////////"<<endl;
}
else
{
for(column=0;column<8;column++)
{
columnRecord[row]=column;
if(panDuan(row))
{
map[row][columnRecord[row]]=1;
putIn(row+1);
map[row][columnRecord[row]]=0;
}
}
}
}

int panDuan (int row)
{
for(int i=0;i<row;i++)
if(columnRecord[row]==columnRecord[i] ||
abs(columnRecord[row]-columnRecord[i])==abs(row-i))
return 0;
return 1;
}

搜索更多相关主题的帖子: void 皇后 include return color 
2005-12-07 13:33
快速回复:[求助]
数据加载中...
 
   



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

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