Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

誰知道八皇后怎麼寫?

0 views
Skip to first unread message

東北一中

unread,
Apr 2, 1998, 3:00:00 AM4/2/98
to

請問有誰知道 八皇后放在八乘八的棋盤上要怎麼做?
--
※ Origin: 楓橋驛站(bbs.cs.nthu.edu.tw) ◆ From: u861848.SHIN12.AB.nthu.edu.tw

愛情無罪

unread,
Apr 2, 1998, 3:00:00 AM4/2/98
to

《 在 worldwid...@bbs.cs.nthu.edu.tw (東北一中) 的大作中提到: 》
: 請問有誰知道 八皇后放在八乘八的棋盤上要怎麼做?
這種問題在資料結購的書中一定找的到答案,
so....到書店或圖書館翻翻就好.

--
[m [1;32m※ 來源:‧蛋捲廣場 bbs.tku.edu.tw‧[FROM: 203.65.191.45] [m

CharlieL

unread,
Apr 3, 1998, 3:00:00 AM4/3/98
to

我知道在

http://www.csie.ntu.edu.tw/~b6506060

我同學的page 上有解

東北一中 撰寫於文章 <3Nj9dG$s...@bbs.cs.nthu.edu.tw>...

啊哈哈

unread,
Apr 5, 1998, 4:00:00 AM4/5/98
to

《 在 SQL@TKU-BBS (愛情無罪) 的大作中提到: 》
: 《 在 worldwid...@bbs.cs.nthu.edu.tw (東北一中) 的大作中提到: 》
: : 請問有誰知道 八皇后放在八乘八的棋盤上要怎麼做?
: 這種問題在資料結購的書中一定找的到答案,
: so....到書店或圖書館翻翻就好.

八個皇后
#include <stdio.h>
#include <conio.h>

int crosscheck(int , int) ;
int verticalcheck(int , int) ;
int safe(int , int) ;
void print(int [][8]) ;
void tryrow(int) ;

static int q[8][8] ;
static cnt = 0 ;

int main(void)
{
int i , j ;

for(i = 0 ; i <= 7 ; i++)
for(j = 0 ; j <= 7 ; j++)
q[i][j] = 0 ;

tryrow(0) ;

return 0 ;
}

int crosscheck(int x , int y)
{
int i , j ;

i = x ;
j = y ;

while( (i > 0) && (j > 0) )
{
i -= 1 ;
j -= 1 ;

if(q[i][j])
return 0 ;
}

i = x ;
j = y ;

while( (i < 7) && (j > 0) )
{
i += 1 ;
j -= 1 ;

if(q[i][j])
return 0 ;
}

return 1 ;
}

int verticalcheck(int x , int y)
{
while(y > 0)
{
y -= 1 ;

if(q[x][y])
return 0 ;
}

return 1 ;
}

int safe(int x , int y)
{
return( crosscheck(x,y) && verticalcheck(x,y) ) ;
}

void print(int a[8][8])
{
int i , j ;

clrscr() ;

gotoxy(21, 4) ; printf("I-------------------------------I") ;
gotoxy(21, 5) ; printf("I I I I I I I I I") ;
gotoxy(21, 6) ; printf("I---+---+---+---+---+---+---+---I") ;
gotoxy(21, 7) ; printf("I I I I I I I I I") ;
gotoxy(21, 8) ; printf("I---+---+---+---+---+---+---+---I") ;
gotoxy(21, 9) ; printf("I I I I I I I I I") ;
gotoxy(21,10) ; printf("I---+---+---+---+---+---+---+---I") ;
gotoxy(21,11) ; printf("I I I I I I I I I") ;
gotoxy(21,12) ; printf("I---+---+---+---+---+---+---+---I") ;
gotoxy(21,13) ; printf("I I I I I I I I I") ;
gotoxy(21,14) ; printf("I---+---+---+---+---+---+---+---I") ;
gotoxy(21,15) ; printf("I I I I I I I I I") ;
gotoxy(21,16) ; printf("I---+---+---+---+---+---+---+---I") ;
gotoxy(21,17) ; printf("I I I I I I I I I") ;
gotoxy(21,18) ; printf("I---+---+---+---+---+---+---+---I") ;
gotoxy(21,19) ; printf("I I I I I I I I I") ;
gotoxy(21,20) ; printf("I-------------------------------I") ;


for( i = 0 ; i <= 7 ; i++ )
for( j = 0 ; j <= 7 ; j++ )
if(a[i][j])
{
gotoxy(i * 4 + 23 , j * 2 + 5) ;
printf("Q") ;
}

gotoxy(32,22) ;
printf("count = %d", cnt) ;
}

void tryrow(int row)
{
int column = 0 ;

do
{
if(safe(column , row))
{
q[column][row] = 1 ;

if(row < 7)
tryrow(row + 1) ;
else
{
cnt += 1 ;
print(q) ;

if(getch() == 0)
{
getch() ;
clrscr() ;
exit(0) ;
}
}

q[column][row] = 0 ;
}

column += 1 ;
}while(column < 8) ;
}
世新資管小薛提供
世新資管小薛提供

--
[m [1;35m※ 來源:‧蛋捲廣場 bbs.tku.edu.tw‧[FROM: 163.30.13.149] [m

0 new messages