集训队专题(8)1008 The Evaluation of Determinant
来源:互联网 发布:知乐油烟机 编辑:程序博客网 时间:2024/05/29 18:57
The Evaluation of Determinant
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 851 Accepted Submission(s): 215
Problem Description
The determinant is quite important in Linear Algebras, but I think that almost everyone who has ever learnt Linear Algebras is tired of the complicated and tedious calculations of determinant. Actually, it’s not the job we should do, isn’t it? As an outstanding Geek, why don’t we just ask computers to do these?
Give you a determinant D (it’s ensured that the result of it is an integer) and m, try to get the result of this determinant mod m, and m = p1 * p2 …… pn, all the pi are different. You can assume 1000 < pi < 10000, aij < 1000, and m can be fit in 32-bit signed integer.
Give you a determinant D (it’s ensured that the result of it is an integer) and m, try to get the result of this determinant mod m, and m = p1 * p2 …… pn, all the pi are different. You can assume 1000 < pi < 10000, aij < 1000, and m can be fit in 32-bit signed integer.
Input
Input two integers n and m in the first line, n represents the scale of the determinant. (n <= 100)
Then comes an n * n matrix, the determinant’s component aij means the one in row i and column j.
Then comes an n * n matrix, the determinant’s component aij means the one in row i and column j.
Output
Output the result of the determinant D mod m.
Sample Input
2 10091 23 4
Sample Output
1007
Source
2009 Multi-University Training Contest 2 - Host by TJU
此题就是一个求行列式对一个数取模的问题,首先我们在输入的时候就可以对每个数进行取模,达到第一层优化,在求行列式需要用到线性代数的知识--高斯消元……这是小编我自己也比较弱的一项,水水的解出来就好了……
#include <cstdio>#include <cstring>#define LL __int64LL num[102][102],tmp,t;int n,m;LL mod(LL a,LL b){if(a<0) return a+b-(a/b)*b;else return a-(a/b)*b;}int main(){LL i,j,k,ans;while(scanf("%d%d",&n,&m)!=EOF){ans = 1;for(i=1; i<=n; i++){for(j=1; j<=n; j++){scanf("%I64d",&num[i][j]);num[i][j] = mod(num[i][j],m); }}for(i=1; i<=n; i++){for(j=i+1; j<=n; j++){while(num[j][i]){t = num[i][i]/num[j][i];for(k=i; k<=n; k++){num[i][k] = mod(num[i][k]-num[j][k]*t,m);tmp = num[i][k];num[i][k] = num[j][k];num[j][k] = tmp;}ans = -ans;}}if(num[i][i] == 0){ans = 0;break;}ans = mod(ans*num[i][i],m);}printf("%I64d\n",ans);}return 0;}
0 0
- 集训队专题(8)1008 The Evaluation of Determinant
- HDU 2827 The Evaluation of Determinant 题解
- Evaluation of Determinant using partial pivoting
- 集训队专题(1)1008 Repository
- 集训队专题(3)1008 最短路
- 集训队专题(5.1)1008 Graph Coloring
- 集训队专题(6)1008 Courses
- 集训队专题(7)1008 Kakuro Extension
- 集训队专题(8)1001 Biorhythms
- 集训队专题(8)1002 X问题
- 集训队专题(8)1007 Remainder
- 集训队专题(8)1009 C Looooopsz
- 集训队专题(3)1009 Choose the best route
- 集训队专题(4)1004 Where is the canteen
- 集训队专题(5.2)1005 The Stable Marriage Problem
- 集训队专题(9)1002 Color the ball
- 集训队专题(8)1003 Chinese remainder theorem again
- 集训队专题(8)1006 Yet Another Multiple Problem
- Guided Filter 引导滤波
- Quartz2D - 图片擦除
- 正确使用#define,const,static,extern
- [转载]startup_stm32f10x_ld_vl.s中的vl是什么意思
- 【C语言】malloc()和free()函数的讲解以及相关内存泄漏问题
- 集训队专题(8)1008 The Evaluation of Determinant
- arp命令
- nyoj 55 懒省事的小明【优先队列】
- Java垃圾回收机制(GC机制)
- 在三大框架里运用lucene和ik分词是报java.lang.reflect.InvocationTargetException异常的解决方法
- HelloWorldApp
- poj 3187 Backward Digit Sums
- python3 目录操作
- 闭包解析