标签: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
原文地址:http://friendsforever.blog.51cto.com/3916357/1649586