八皇后問題用c 窗體程式如何實現

2025-05-07 19:30:07 字數 3446 閱讀 2940

1樓:網友

c#下的八皇后效率很低,winform比控制檯還低。建議用c,c++實現。

2樓:網友

我能向你們學習嗎~你們好厲害##

八皇后問題求解的c語言程式的實現

3樓:網友

這是個前不久,我為別人寫的乙個**;

八皇后問題共有92種解;

以下**是解決:對於固定乙個皇后位置,輸出所有可能情況。

如果這不適合你的答案你可以,稍微改改的哦~~**如下:#include ""

bool board[8][8]=;

int num=0; //滿足條件的個數。

int inix,iniy; //輸入乙個皇后的初始位置void output() //輸出。

int i, j;

for(i=0;i<8;i++)

for(j=0;j<8;j++)

if(!board[i][j]) printf("■ ");

else printf("◆ ");

printf("");

num++;

printf("");

return ;

bool check(int x,int y) //判斷是否能放int i, j ;

for(i=0; i<8 ; i++)

if(board[i][y]==1) return false;

for(i=0;i<8;i++)

if(board[x][i]==1) return false;

i=x; j=y;

while(i>0 &&j>0 )

for(;i<8 &&j<8 ; i++,j++)if(board[i][j]==1) return false;

i=x; j=y;

while(i>0 &&j<7 )

for(;i<8 &&j>=0 ; i++ j--)if(board[i][j]==1) return false ;

return true ;

if(num>=8)

if(x==inix-1) search(inix,num+1); else

for(i=0;i<8;i++)

if(check(x,i))

board[x][i]=1;

search(x+1,num+1);

board[x][i]=0;

return ;

int main()

scanf("%d %d",&inix,&iniy);

board[inix-1][iniy-1] = 1 ;

search(0,0);

printf("%d",num);

return 0;

例如: 輸入 : 1 1 輸出 :

4樓:網友

此程式可解決n後問題,但輸出效果沒有上面的好。

#include

const int n = 20;

void main()

cout<<"n後問題";

int n, m, good, col[n+1], a[n+1], b[2*n+1], c[2*n+1], j;

cout<<"n = "; cin>>n;

for(j = 0; j <= n; j++)a[j] = 1;

for(j = 0; j <= 2*n; j++)b[j] = c[j] = 1;

m = col[1] = good = 1; col[0]=0;

do {if(good) {

if(m == n) {

cout<<" 列 行";

for(j = 1; j <= n; j++)cout<<" "<>n;

5樓:網友

#include

int q[20];

void queens(int,int);

int place(int,int);

void print(int);

int main()

int n;

printf("您要求的是幾皇后問題?");

scanf("%d",&n);

queens(1,n);

system("pause");

return 0;

void queens(int k,int n)int i;

if(n\t",i,q[i]);

printf("");

用c編八皇后動態模擬的程式中怎樣實現棧及其中變化

6樓:網友

public userdwname as stringpublic username as stringpublic userright as stringpublic conn as stringprivate sub command1_click()dim password as stringdim respond as stringusername =

password =

on error goto err1

conn select * from 使用者登入 where 使用者名稱=" username & and " 密碼="亮旅 & password &

if = adposunknown thenrespond = msgbox("使用者名稱或密碼錯誤,請重新輸入!型擾", vbokonly, "警告卜鍵旦")

if respond <>vbokonly then=

username =

password =

end if

else userright = "許可權")unload frmlogin

end if

exit sub

err1:msgbox "系統配置錯誤!無法與伺服器連線!"

userright = 0"

unload me

end sub

private sub command2_click()end end sub

private sub form_load()=

conn =

conn = provider=;integrated security=sspi;persist security info=false;initial catalog=生產排產單;data source=f70e4f38300d42f"

end sub

private sub text2_change()end sub

八皇后c語言程式及實驗報告

7樓:網友

這個有點難度。

不好意思。

8樓:來鑲天

這個要怎麼寫啊。不就是回溯法。難道還團野要舉幾個回溯法的例子給你們老師嗎?

我接下塌巖喊了。今天晚上給棗棚你搞定。

c 如何實現窗體上按鈕開啟另窗體

首先,為form1,form2,新增兩 抄個襲類,如 form1,from2 其次,給button新增單擊事件 再次,在1類的源程式中包含2類標頭檔案,如 在form1.cpp中 include form2.h 最後在單擊事件中新增 form2 fm fm.domodal 1.先新新增一個來對話方塊...

用C 實現進位制間轉換的程式

計算機內部都是用二進位制儲存資料的,沒有什麼2,8,16進位制的區別,只是展現方式不同而已。所以,不需要什麼轉換函式。為了人們通常的閱讀習慣,裡若沒有顯示指明,則預設為10進位制。例如 include using namespace std void main 輸出 oct 20 hex 10 de...

用C 實現迴圈顯示,當輸入字元N時終止程式

下面是 用一個子執行緒控制輸入,主執行緒負責列印,有問題內hi我 include include include dword winapi getchar lpvoid lpparameter thread data char c 1 int main dword winapi getchar lp...