java关于国际象棋8个皇后的问题 在国际象棋的棋盘上,放置8个皇后,如何放才能使得这8个皇后无论横看竖看斜看都不在同一条直线上. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 X o o o o o o oo o x o o o o oo o o o x o o oo o o o o o x oo x o o o o o oo o o x o o o oo o o o o x o oo o o o o o o x 在度娘、谷歌如此遍历的今天LZ还是要来CSDN发帖求助我只能说LZ的分实在太多没地方花要不这样吧,LZ就把这贴当散分吧? 结贴!代码://Queens.java//国际象棋8个皇后,使得8个皇后无论横看竖看斜看都不在同一条直线上import javax.swing.*;public class Queens{ int[] a =new int[8]; int[] b =new int[15]; int[] c =new int[15]; int[][] Queen=new int[8][8]; void next(int i) { for(int j=0;j<8;j++) { if(a[j]==0&&b[i+j]==0&&c[i-j+7]==0) { a[j]=b[i+j]=c[i-j+7]=1; Queen[i][j]=1; if(i<7) next(i+1); else { String output=new String(); for(int m=0;m<8;m++) { for(int n=0;n<8;n++) output+=" "+Queen[m][n]+" "; output+="\n"; } JTextArea outputArea=new JTextArea(); outputArea.setText(output); JOptionPane.showMessageDialog(null,outputArea,"One possible distribution",JOptionPane.INFORMATION_MESSAGE); } a[j]=b[i+j]=c[i-j+7]=Queen[i][j]=0; } } } public static void main(String args[]) { Queens one=new Queens(); one.next(0); System.exit(0); } }其他算法>>百度百科:http://baike.baidu.com/view/622604.htm--4楼 只需百度一下就可得40分,你都不去.还散分? java源码阅读求指导,有这发面经验的同仁给点建议哈! 对J2SE掌握到哪个程度可以开始进行J2EE之旅 JAVA的List问题 正则表达式 求助 谁能写出这个程序? [求教]如何在工具栏中加入下拉文本框? 求CSDN高手点拨一个“CS结构聊天系统”的“集成测试”中的问题... 新手求一概率问题 请问:在midp中如何访问手机的内部文件呀“例如:通讯录” jna调用FindWindow()方法出错 Cannot initialize context because there is already a root application 刚刚开始学java 请高手指点一下 我该怎么做
o o x o o o o o
o o o o x o o o
o o o o o o x o
o x o o o o o o
o o o x o o o o
o o o o o x o o
o o o o o o o x
代码:
//Queens.java
//国际象棋8个皇后,使得8个皇后无论横看竖看斜看都不在同一条直线上
import javax.swing.*;
public class Queens
{
int[] a =new int[8];
int[] b =new int[15];
int[] c =new int[15];
int[][] Queen=new int[8][8];
void next(int i)
{
for(int j=0;j<8;j++)
{
if(a[j]==0&&b[i+j]==0&&c[i-j+7]==0)
{
a[j]=b[i+j]=c[i-j+7]=1;
Queen[i][j]=1;
if(i<7)
next(i+1);
else
{
String output=new String();
for(int m=0;m<8;m++)
{
for(int n=0;n<8;n++)
output+=" "+Queen[m][n]+" ";
output+="\n";
}
JTextArea outputArea=new JTextArea();
outputArea.setText(output);
JOptionPane.showMessageDialog(null,outputArea,"One possible distribution",JOptionPane.INFORMATION_MESSAGE);
}
a[j]=b[i+j]=c[i-j+7]=Queen[i][j]=0;
}
}
}
public static void main(String args[])
{
Queens one=new Queens();
one.next(0);
System.exit(0);
}
}其他算法>>
百度百科:http://baike.baidu.com/view/622604.htm--4楼 只需百度一下就可得40分,你都不去.还散分?