// Author: Manfred Scheucher // Date : 12.06.2015 #include #include #include #include #define MAXN 16 #define ATTACKS 1 int queenx[MAXN]; // x coordinate int queeny[MAXN]; // y coordinate int queena[MAXN][MAXN]; // after i iterations queen j is attacked by queena[i][j] queens char field[MAXN][MAXN]; char field1[MAXN][MAXN]; char field2[MAXN][MAXN]; long ct = 0; int n,N; inline int to_field() { int x,y; for(y=0;y field1[x][y]) return 0; } } return 0; } inline int islexmin() { to_field(); memcpy(field1,field,MAXN*MAXN*sizeof(char)); // rot 90 rot(); memcpy(field1,field2,MAXN*MAXN*sizeof(char)); if(cmp()) return 0; // rot 180 rot(); memcpy(field1,field2,MAXN*MAXN*sizeof(char)); if(cmp()) return 0; // rot 270 rot(); memcpy(field1,field2,MAXN*MAXN*sizeof(char)); if(cmp()) return 0; // mirrored 0 memcpy(field1,field,MAXN*MAXN*sizeof(char)); flip(); memcpy(field1,field2,MAXN*MAXN*sizeof(char)); if(cmp()) return 0; // mirrored 90 rot(); memcpy(field1,field2,MAXN*MAXN*sizeof(char)); if(cmp()) return 0; // mirrored 180 rot(); memcpy(field1,field2,MAXN*MAXN*sizeof(char)); if(cmp()) return 0; // mirrored 270 rot(); memcpy(field1,field2,MAXN*MAXN*sizeof(char)); if(cmp()) return 0; return 1; } inline int valid(int k) { int i, prev, dx, dy; queena[k][k] = 0; for(i=0;iATTACKS || queena[k][k]>ATTACKS) return 0; } if(k==N-1 && queena[k][i]!=ATTACKS) return 0; } if(k==N-1 && queena[k][k]!=ATTACKS) return 0; return 1; } int place(int k) { int x,y; if(k==N && islexmin()) { ct++; print(); } else { for(y=0;y0 && (y