-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUVa-750.cpp
More file actions
55 lines (42 loc) · 1.07 KB
/
UVa-750.cpp
File metadata and controls
55 lines (42 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
54
55
#include <bits/stdc++.h>
#define vi vector<int>
using namespace std;
void search (int c, int a, int b);
bitset<8> rw;
bitset<15> rd;
bitset<15> ld;
int linecounter = 0;
int row[8];
int main() {
int tc;
scanf("%d\n\n", &tc);
int a, b;
while (tc--) {
printf("SOLN COLUMN\n");
printf(" # 1 2 3 4 5 6 7 8\n\n");
linecounter = 0;
rw.reset();
rd.reset();
ld.reset();
memset(row, 0, sizeof(row));
scanf("%d %d", &a, &b);
search(0, a-1, b-1);
if (tc) printf("\n");
}
}
void search (int c, int a, int b) {
if (c == 8 and row[b] == a) {
printf("%2d %d", ++linecounter, row[0]+1);
for (int j = 1; j < 8; ++j) printf(" %d", row[j]+1);
printf("\n");
return;
}
for (int r = 0; r < 8; r++) {
if (c == b && r != a) continue;
if (!rw[r] && !rd[r+c] && !ld[r-c+8-1]) {
rw[r] = rd[r+c] = ld[r-c+8-1] = 1;
row[c] = r, search(c+1,a,b);
rw[r] = rd[r+c] = ld[r-c+8-1] = 0;
}
}
}