-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path750.cpp
More file actions
53 lines (49 loc) · 1.07 KB
/
750.cpp
File metadata and controls
53 lines (49 loc) · 1.07 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
#include <bits/stdc++.h>
using namespace std;
int a[10], n = 8, I = 1, X, Y;
int check(int k, int y) {
if (y == Y) return 0;
if (abs(X - k) == abs(Y - y)) return 0;
int i;
for (i = 1; i < k; i++) {
if (a[i] == y) return 0;
if (abs(a[i] - y) == abs(k - i)) return 0;
}
return 1;
}
int call(int k) {
int i;
if (k >= n + 1) {
printf("%2d ", I);
I++;
for (i = 1; i <= n; i++) printf(" %d", a[i]);
printf("\n");
}
for (i = 1; i <= n; i++) {
if (i != Y)
if (check(k, i)) {
a[k] = i;
if (X != k + 1)
call(k + 1);
else
call(k + 2);
}
}
}
int main() {
int i = 0, t;
scanf("%d", &t);
while (t--) {
scanf("%d %d", &Y, &X);
a[X] = Y;
I = 1;
if (i != 0) printf("\n");
printf("SOLN COLUMN\n # 1 2 3 4 5 6 7 8\n\n");
if (X != 1)
call(1);
else
call(2);
i++;
}
return 0;
}