U E D R , A S I H C RSS

Eight Queen Problem/이준욱

8Bit Version
~cpp 
#include <stdio.h>
#define MASK 0x01
unsigned char rmap[8], map[8] = {0,0,0,0,0,0,0,0};
 
void result(void)
{
    int i = 0;
    for (printf("\nResult: "); i < 8 ; printf("[%2x] ", rmap[i++]));
}
int mask(unsigned char * tmap ,  register int x, register int y)
{
    register int i;
 
    if(map[y] & MASK << x) return 0;
    memcpy(tmap, map, 8);
    rmap[y] = MASK << x;
    map[y] |= 0xff;
    for (i = 0;i < 8;i++)
        map[i] |=  (MASK << x) | (MASK << (x - y + i)) | (MASK << (x + y - i));
 
    return 1;
}
void checkQueen(int depth)
{
    int i;
    unsigned char tmap[8];
 
    for( i = 0;i < 8 && depth < 8;i++) {
        if(mask(tmap, i, depth)) {
            if((depth + 1) == 8) result();
            checkQueen(depth + 1);
            memcpy(map, tmap, 8);
        }
    }
}
int main()
{
    checkQueen(0);
    return 0;
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:12
Processing time 0.0136 sec