SPOJ 2832 DETER3 - Find The Determinant III(矩阵行列式)
来源:互联网 发布:python socket 10022 编辑:程序博客网 时间:2024/05/21 06:22
DETER3 - Find The Determinant III
no tags
点击打开链接
Given a NxN matrix A, find the Determinant of A % P.
Input
Multiple test cases (the size of input file is about 3MB, all numbers in each matrix are generated randomly).
The first line of every test case contains two integers , representing N (0 < N < 201) and P (0 < P < 1,000,000,001). The following N lines each contain N integers, the j-th number in i-th line represents A[i][j] (- 1,000,000,001 < A[i][j] < 1,000,000,001).
Output
For each test case, print a single line contains the answer.
Example
Given a NxN matrix A, find the Determinant of A % P.
Input
Multiple test cases (the size of input file is about 3MB, all numbers in each matrix are generated randomly).
The first line of every test case contains two integers , representing N (0 < N < 201) and P (0 < P < 1,000,000,001). The following N lines each contain N integers, the j-th number in i-th line represents A[i][j] (- 1,000,000,001 < A[i][j] < 1,000,000,001).
Output
For each test case, print a single line contains the answer.
Example
Input:
1 10
-528261590
2 2
595698392 -398355861
603279964 -232703411
3 4
-840419217 -895520213 -303215897
537496093 181887787 -957451145
-305184545 584351123 -257712188
Output:
0
0
2
求出矩阵的行列式,模p
伪代码:
#include <map> #include <set> #include <queue> #include <stack> #include <vector> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const double pi = acos(-1); const int inf = 0x3f3f3f3f; const double eps = 1e-15; typedef long long LL; typedef pair <int, int> PLL; const int N = 300; LL mat[N][N]; LL Det (int n, int mod) //按列化为下三角 { for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { mat[i][j] %= mod; } } LL res = 1; for(int i = 0; i < n; ++i) { if (!mat[i][i]) { bool flag = false; for (int j = i + 1; j < n; ++j) { if (mat[j][i]) { flag = true; for (int k = i; k < n; ++k) { swap (mat[i][k], mat[j][k]); } res = -res; break; } } if (!flag) { return 0; } } for (int j = i + 1; j < n; ++j) { while (mat[j][i]) { LL t = mat[i][i] / mat[j][i]; for (int k = i; k < n; ++k) { mat[i][k] = (mat[i][k] - t * mat[j][k]) % mod; swap (mat[i][k], mat[j][k]); } res = -res; } } res = (res * mat[i][i]) % mod; } return (res + mod) % mod;}int main(){ freopen("in.txt","r",stdin); int n; LL p; while (~scanf("%d%I64d",&n, &p)) { for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { scanf("%I64d",&mat[i][j]); } } LL ans = Det (n, p); printf("%I64d\n",ans); } return 0;}
0 0
- SPOJ 2832 DETER3 - Find The Determinant III(矩阵行列式)
- SPOJ DETER3 Find The Determinant III(求行列式的秩、高斯消元)
- SPOJ-Find The Determinant III(矩阵行列式)
- SPOJ (不知道题号是多少) DETER3 - Find The Determinant III
- SPOJ DETER3 (矩阵行列式)
- Find The Determinant III SPOJ
- SPOJ2832--- Find The Determinant III
- bzoj 2107 Spoj2832 Find The Determinant III
- 线性代数笔记(4):行列式(determinant)
- UVA 684 - Integral Determinant(行列式变换)
- uva 684 - Integral Determinant(行列式求值)
- 矩阵行列式
- 行列式(determinant)的物理意义及性质
- Determinant
- 矩阵·叉姐出的两道Determinant
- 求解矩阵行列式
- 矩阵行列式det()
- ACM矩阵行列式计算
- VMWARE桥接方式上网【针对公司静态IP】
- 【sdut】 [1298] 活动选择
- Web开发步骤
- acm题为什么总是出现wrong answer。。。求大神救助
- 优秀项目经理应备技能06-项目组织的特性与类型
- SPOJ 2832 DETER3 - Find The Determinant III(矩阵行列式)
- UI-UILabel
- Class org.apache.struts2.json.JSONWriter can not access a member of class oracle.jdbc.driver.Physica
- Struts(19)Struts集成
- C语言编程中的问题
- HDU 5407(2015多校10)-CRB and Candies(组合数最小公倍数+乘法逆元)
- Android source build/envsetup.sh 及lunch 过程
- POJ 2478 Farey Sequence
- 留几手:互联网创业到底是咋回事(说得真经典,创业者不创业的都值得一看)