Topic Link:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&itemid=8&page=show_problem& problem=625
Test instructions: An n-order determinant is given, and the value is evaluated.
Idea: Template reference http://blog.csdn.net/zhoufenqin/article/details/7779707:
the nature of the N-Step determinant:
Property 1: The determinant is equal to his transpose determinant.
Property 2: Two rows (columns) of an interchange determinant, determinant.
corollary: If there are two rows of corresponding elements in a determinant (that is, the same element as the column labeled), the determinant is zero.
Property 3: The common factor K of a row in the determinant, you can refer to the outside of the determinant.
corollary: When two rows (column) elements in the determinant correspond proportionally, the determinant is equal to zero.
Property 4: Determinant has branch (column) additive.
corollary: If each element of a row (column) of a determinant is written as the sum of the number of M (an integer greater than 2), then the determinant can be written as a sum of M-determinant.
Property 5: Determinant one row (column) each element is multiplied by the same number and added to the corresponding element of another row (column), the determinant is unchanged.
can transform the original determinant into the upper triangle or the lower triangular determinant, then the determinant value is the product of the diagonal.
1#include <iostream>2#include <cstring>3#include <cstdio>4 using namespacestd;5 intN;6 inta[ *][ *];7 voiddeterminant ()8 {9 intCNT =0;Ten intAns =1; One for(inti =1; I <= N; i++) A { - for(intj = i+1; J <= N; J + +) - { the intx, y; -x = i, y =J; - while(A[y][i]) - { + intt = a[x][i]/A[y][i]; - for(intK =1; K <= N; k++) + { AA[X][K] = a[x][k]-a[y][k]*T; at } - swap (x, y); - } - if(X! =i) - { - for(intK =1; K <= N; k++) in { - swap (A[x][k], a[y][k]); to } +CNT ^=1; - } the } * if(A[i][i] = =0) $ {Panax NotoginsengAns =0; Break; - } the ElseAns *=A[i][i]; + } A if(CNT) ans *=-1; theprintf"%d\n", ans); + } - intMain () $ { $ //freopen ("In.txt", "R", stdin); - while(SCANF ("%d", &N)) - { the if(n = =0) - {Wuyiprintf"*\n"); the Break; - } Wu for(inti =1; I <= N; i++) - { About for(intj =1; J <= N; J + +) $ { -scanf"%d", &a[i][j]); - } - } A determinant (); + } the return 0; -}
UVA 684 Integral determinant determinant evaluation