码迷,mamicode.com
首页 > 编程语言 > 详细

java eight_queue

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

标签:java

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

标签:java

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!