八皇后问题代码 那位大虾帮修改一下

李万鹏 2010-01-24 08:16:46
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
struct Node{
int x;
int y;
};
int main(){
int i,j;
int a[8][8];
Node stack[8];
int top = -1, bottom = -1;
for( i = 0; i < 8; i++)
for( j = 0; j < 8; j++){
while( bottom <= top ){
if(i != stack[bottom].x && j != stack[bottom].y && (abs( i - stack[bottom].x) != abs(j - stack[bottom].y))){
bottom++;
continue;
}
else
break;
}
if(bottom > top)
stack[++top] = a[i][j];
else
top--;
}
}
for( i = 0; i < 8; i++)
printf("(%d,%d)",stack[i].x,stack[i].y);
system("pause");
return 0;
}


...全文
145 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
李万鹏 2010-01-24
  • 打赏
  • 举报
回复
c[i+j]=1; /*占领两个对角线*/
d[i-j+7]=1;
是什么意思啊
李万鹏 2010-01-24
  • 打赏
  • 举报
回复
用一个栈存放找好的 用指针操作下标来模拟栈
z569362161 2010-01-24
  • 打赏
  • 举报
回复
int main(){
int i,j;
int a[8][8];
Node stack[8]; //这是什么?
z569362161 2010-01-24
  • 打赏
  • 举报
回复
晕死了,你对照还看不出来
李万鹏 2010-01-24
  • 打赏
  • 举报
回复
可我的哪错了呀 帮看看呗 跪求
z569362161 2010-01-24
  • 打赏
  • 举报
回复
http://topic.csdn.net/u/20100108/19/5ab70271-905e-4223-9a72-4c0311ac4476.html?0879974018900353



这里就有,慢慢研究
z569362161 2010-01-24
  • 打赏
  • 举报
回复
没仔细看。

给你点源码。自己对照

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧