1樓:
樓主你好。見醜了。。我用了乙個窮舉的方法。我寫的**的好處在於易於擴充套件,n代表了棋盤的大小,你可以任意修改,不止是4。
【經過幾次優化後變為以下**,採用回溯法】
#include
#include
#define n 6
#define noprinting //標誌是否列印陣列
//如果只是計算可能的情況的話,根本不需要n×n的棋盤陣列。
void printmatrix(int* matrix, int m, int n)
printf("\n");}}
void recusion(int* chessboard, int n, int iter, int* count, int* col)
for(i=0;i
#ifndef noprinting
currentrow[i]=currentrow[j]=0;//清空當前行
#endif}}
}void putchess(int* chessboard, int n, int* count)
void main();
printf("**********start to put chess!**********=\n");
printf("all %d possible deploy!\n", count);
}輸出:
【n為3且選擇列印】
**********start to put chess!**********=
1 1 0
1 0 1
0 1 1
******************************=
1 1 0
0 1 1
1 0 1
******************************=
1 0 1
1 1 0
0 1 1
******************************=
1 0 1
0 1 1
1 1 0
******************************=
0 1 1
1 1 0
1 0 1
******************************=
0 1 1
1 0 1
1 1 0
******************************=
all 6 possible deploy!
press any key to continue
【n為8的時候,有近兩億種情況,花了將近一分鐘的時間算完。】
**********start to put chess!**********=
all 187530840 possible deploy!
press any key to continue
2樓:mis_丫
要列出所有情況?
不現實吧,太多了,算出有幾種還可以
只要一種那你直接指定位置就好了啊
比如:a[0][0] ,a[0][1],
a[1][0] ,a[1][1],
a[2][2] ,a[2][3],
a[3][2] ,a[3][3],
3樓:匿名使用者
編的話我應該會,你說的數學情況我不大懂
是說每行列最多兩個,還是都要有兩個呢?
4樓:匿名使用者
情況比較複雜,最好從每行每列放乙個開始吧。
5樓:愛我所愛
只是純粹的放置標誌量麼?有沒有遊戲規則什麼的
c語言編寫乙個程式,實現乙個3×4矩陣轉置。
6樓:匿名使用者
思路:定了bai兩個二維陣列分du別儲存轉置前zhi後的矩陣,接著for迴圈依次轉置dao即可。內//參考**
#include
int main()
,,},b[4][3];
int i,j;
for(i=0;i<3;i++)
for(j=0;j<4;j++)
容b[j][i]=a[i][j];
for(i=0;i<4;i++)
return 0;}/*
執行結果:
1 5 9
2 6 10
3 7 11
4 8 12*/
7樓:匿名使用者
#include
void main()
for(i=0;i
for(j=0;j
b[j][i]=a[i][j];
for(i=0;i
請問C語言程式將下列程式補充完整,練習結構體變數作為函式引數和函式返回值的方法
親,你這裡寫的是 void fun int a,float b,char c 20 fun函式裡面要傳入的不是位址而是值,你只要把 fun s.a,s.b,s.c 改為 fun s.a,s.b,s.c 就行 希望採納!c example2 錯了,c 20 代表字元陣列,c代表位址,不能這樣賦值 c語...
求助大神解決c語言程式設計程式作業,求助大神C語言程式設計解決問題
include include int main return 0 星期五 的 的期望 打算打算 非完全無法 取得其完全我 地區的期望愛上 求助大神c語言程式設計解決問題 這個程式就是運算元組嘛 留一下郵箱交流,我幫你解決 c語言程式設計題,求助大神!include include define n...
求c 大神幫忙寫c 程式!!謝謝
請問是先輸入矩陣a再輸入向量x嗎?我沒做資料測試,你自己試一下看看可不可以,有問題我再改。include include include include define maxn 100 5 using namespace std typedef long long ll struct matrix ...