如何取矩陣各行的最大值來比大小 |
答題得分者是:yulong375
|
hsiang730229
一般會員 發表:1 回覆:1 積分:0 註冊:2008-03-03 發送簡訊給我 |
各位大大好: 我想將以下程式修改成:兩個矩陣Q與r的各行先取一個最大值後.再來比大小.我的定理為:如果Q[ j ][ k ]的每一行的最大值都大於等於r[ i ][ k ]的每一行的最大值 則有可能有解 請問該如何修改
[code cpp] int i,j,k; int CheckCount; for(i=0;i CheckCount=0; for(j=0;j CheckCount ; if(CheckCount==QRow) { NoSolutionRdoBtn->Checked=true; NoSolutionRdoBtn->Font->Color=clRed; } else MaybeHasSolutionRdoBtn->Checked=true; } GroupBox2->Enabled=true; [/code] |
yulong375
一般會員 發表:2 回覆:22 積分:19 註冊:2007-03-15 發送簡訊給我 |
把你的程式改成這樣看看
[code cpp] #define max(a,b) ((a) > (b) ? (a) : (b)) #define min(a,b) ((a) < (b) ? (a) : (b)) //--------------------------------------------------------------- int CheckCount; CheckCount=0; for(int k=0;k int rRowmax=0, for(int i=0;i int QRowmax=0; for(int j=0;j if(rRowmax > QRowmax) CheckCount ; } if(CheckCount==rCol) { NoSolutionRdoBtn->Checked=true; NoSolutionRdoBtn->Font->Color=clRed; } else MaybeHasSolutionRdoBtn->Checked=true; [/code]
------
我還是很新的新手,如果回答的太笨拙還請各位多多包含!! |
hsiang730229
一般會員 發表:1 回覆:1 積分:0 註冊:2008-03-03 發送簡訊給我 |
|
yulong375
一般會員 發表:2 回覆:22 積分:19 註冊:2007-03-15 發送簡訊給我 |
抱歉,我誤會你意思了。
更改一下,我做了個範例: [code cpp] #define max(a,b) ((a) > (b) ? (a) : (b)) #define min(a,b) ((a) < (b) ? (a) : (b)) //============================= void __fastcall TForm1::Button1Click(TObject *Sender) { int CheckCount; int rRowmax=0; int QRowmax=0; int r[4][3]={{1, 2, 3},{1, 2, 3},{1, 2, 3},{2, 3, 4}}; int Q[3][3]={{1, 2, 3},{1, 2, 3},{1, 2, 3}}; CheckCount=0; for(int k=0;k<3;k ) { for(int i=0;i<4;i ) rRowmax = max(rRowmax, r[i][k]); for(int j=0;j<3;j ) QRowmax = max(QRowmax, Q[j][k]); if(rRowmax > QRowmax) CheckCount ; } if(CheckCount==3) Label1->Caption="1"; else Label1->Caption="2"; } [/code] 執行結果=1。
------
我還是很新的新手,如果回答的太笨拙還請各位多多包含!! |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |