在国际象棋的棋盘上,放置8个皇后,如何放才能使得这8个皇后无论横看竖看斜看都不在同一条直线上.

解决方案 »

  1.   

    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 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
      

  2.   

    在度娘、谷歌如此遍历的今天LZ还是要来CSDN发帖求助我只能说LZ的分实在太多没地方花要不这样吧,LZ就把这贴当散分吧?
      

  3.   

    结贴!
    代码:
    //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分,你都不去.还散分?