-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodinter9.9(2).java
64 lines (60 loc) · 1.43 KB
/
codinter9.9(2).java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import java.util.*;
public class CodInter {
public static void main(String argc[]){
ArrayList<Point> al=new ArrayList<Point>();
boolean row[]=new boolean [8];
boolean column[]=new boolean [8];
boolean dial1[]=new boolean [15];
boolean dial2[]=new boolean [15];
getAns(-1,0,al,row,column,dial1,dial2);
}
public static void getAns(int i,int j,ArrayList<Point> al,boolean row[],boolean column[],boolean dial1[],boolean dial2[]){
if(i!=-1){
if(row[i]||column[j]||dial1[i-j+7]||dial2[i+j]) return;
al.add(new Point(i,j));
if(i==7){
print(al);
al.remove(al.size()-1);//!!!!!
return;
}
row[i]=true;
column[j]=true;
dial1[i-j+7]=true;
dial2[i+j]=true;
for(int jj=0;jj<8;jj++){
getAns(i+1,jj,al,row,column,dial1,dial2);
}
row[i]=false;
column[j]=false;
dial1[i-j+7]=false;
dial2[i+j]=false;
al.remove(al.size()-1);
}
else{
for(int jj=0;jj<8;jj++){
for(int temp=0;temp<8;temp++){
row[temp]=false;
column[temp]=false;
}
for(int temp=0;temp<14;temp++){
dial1[temp]=false;
dial2[temp]=false;
}
getAns(i+1,jj,al,row,column,dial1,dial2);
}
}
}
public static void print(ArrayList<Point> al){
for(Point p:al){
System.out.print("("+p.x+","+p.y+")"+" ");
}
System.out.println();
}
}
class Point{
int x;int y;
Point(int a,int b){
x=a;
y=b;
}
}