-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp1220.cpp
More file actions
95 lines (89 loc) · 2.15 KB
/
Copy pathp1220.cpp
File metadata and controls
95 lines (89 loc) · 2.15 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include<bits/stdc++.h>
using namespace std;
int huanghou(int i,int w[]);
int num=0;
int main(){
int a,b;
int w[8];
while(scanf("%d",&a)!=EOF){
for(int i=0;i<8;i++){
w[i]=-99;
}
for(int i=0;i<8;i++)
for(int j=0;j<8;j++){
if(i==0&&j==0){
if(a==1){
w[i]=j;
}
}else{
scanf("%d",&b);
if(b==1){
w[i]=j;
}
}
}
huanghou(0,w);
printf("%d\n",num);
num=0;
for(int i=0;i<8;i++){
w[i]=-99;
}
}
}
int huanghou(int i,int w[]){
int sum=0;
if(w[7]!=-99&&i==7){
num++;
return 0;
}
else if(i==7){
for(int j=0;j<8;j++){
bool f=true;
for(int m=0;m<7;m++){
bool flag=true;
double c=abs((w[m]-j)*1.0)/((i-m)*1.0);
if(c==1||c==0){
flag=false;
}
if(!flag){
f=false;
break;
}
}
if(f)
num++;
}
return 0;
}
else{
if(w[i]!=-99){
huanghou(i+1,w);
}else{
for(int j=0;j<8;j++){
// cout<<i<<','<<j<<endl;
bool f=true;
for(int m=0;m<8;m++){
if(m==i)
continue;
else{
bool flag=true;
double c=abs((w[m]-j)*1.0)/((i-m)*1.0);
if(c==1||c==0){
flag=false;
}
// cout<<i<<' '<<j<<' '<<flag<<' '<<m<<' '<<w[m]<<' '<<c<<' '<<endl;
if(!flag){
f=false;
break;
}
}
}
if(f){
w[i]=j;
huanghou(i+1,w);
w[i]=-99;
}
}
}
}
}