-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
83 lines (72 loc) · 1.79 KB
/
main.c
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
#include <stdio.h>
#define N 10
static unsigned int buf[N];
#define CLEAN_BUFF() do{\
for(unsigned char t = 0; t < N; t++)\
buf[t] = 0;\
} while(0);
#define ABS(x) (((x)>=0)?(x):(x)*-1)
unsigned char isLeagul(unsigned int x, unsigned int y);
static void q();
static void console(unsigned long int t);
unsigned long int result = 0;
int main() {
CLEAN_BUFF();
q();
console(result);
}
unsigned char isLeagul(unsigned int x, unsigned int y) {
unsigned int coluOr = 0;
for(unsigned char i = 0; i < N; i++) {
coluOr |= buf[i] & x;
}
unsigned int delta = 0;
for(unsigned char i = 0; i < N; i++) {
delta |= ((buf[i]>>ABS(y-i)) | (buf[i]<<ABS(y-i))) & x;
}
if((buf[y]==0) && (coluOr==0) && (delta == 0))
return 1;
else
return 0;
}
void q() {
unsigned int y = 0, x = 1;
while(y < N) {
while(x < 1<<N) {
if(isLeagul(x, y)) {
buf[y] = x;
x = 1;
break;
} else {
x = x<<1;
}
}
if(buf[y]==0) {
if(y == 0)
break;
else {
y--;
x = buf[y]<<1;
if(x==0)
x=1;
buf[y] = 0;
continue;
}
}
if(y == N-1) {
result++;
x = buf[y]<<1;
buf[y] = 0;
continue;
}
y++;
}
}
void console(unsigned long int t) {
printf("%d: %03d-----\n", N, t);
// for(unsigned char i = 0; i < N; i++) {
// for(unsigned char b = 0; b < N; b++)
// printf("%d ", buf[i]>>b & 1);
// printf("\n");
// }
}