首页 > 编程语言 > 详细

java eight_queue

时间:2015-05-08 15:06:07      阅读:221      评论:0      收藏:0      [点我收藏+]

public class Test {

public void calmaze(int[][] pmaze, int nlvl){

for(int i = 0; i < pmaze.length; i++){

if(justplay(pmaze, nlvl, i)){

pmaze[nlvl][i] = 1;

}else{

continue;

}

if(nlvl == 7){

display(pmaze);

}else{

calmaze(pmaze, nlvl + 1);

}

for(int j = 0; j < pmaze.length; j++){

pmaze[nlvl][j] = 0;

}

}

}

public boolean justplay(int[][] pmaze, int row, int col){

boolean flag = false;

if(row == 0)

return true;

int tmprow = row, tmpcol = col;

while(tmprow > 0 && tmpcol > 0){

if(pmaze[tmprow - 1][tmpcol - 1] == 1){

return flag;

}

tmprow--;

tmpcol--;

}

tmprow = row;

tmpcol = col;

while(tmprow > 0 && tmpcol<pmaze.length-1){

if(pmaze[tmprow - 1][tmpcol + 1] == 1){

return flag;

}

tmprow--;

tmpcol++;

}

tmprow = row;

while(tmprow > 0){

if(pmaze[tmprow - 1][col] == 1){

return flag;

}

tmprow--;

}

return true;

}

public void display(int[][] pmaze){

int i = 0, j = 0;

System.out.println("the "+seq++ +"th times");

for(i = 0; i < pmaze.length; i++){

for(j = 0; j < pmaze[i].length; j++){

if(pmaze[i][j] == 0){

System.out.print("*");

}else{

System.out.print("#");

}

}

System.out.println();

}

}

}

本文出自 “welcome” 博客,请务必保留此出处http://friendsforever.blog.51cto.com/3916357/1649586

java eight_queue

原文:http://friendsforever.blog.51cto.com/3916357/1649586

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!