ACM矩阵行列式计算
来源:互联网 发布:淘宝苹果配件 编辑:程序博客网 时间:2024/04/30 02:29
#include<iostream>#include<cstdio>#include<cmath>using namespace std;typedef __int64 lld;lld a[205][205];int sign;lld N,MOD;void solved(){ lld ans=1; for(int i=0;i<N;i++)//当前行 { for(int j=i+1;j<N;j++)//当前之后的每一行,因为每一行的当前第一个数要转化成0(想想线性代数中行列式的计算) { int x=i,y=j; while(a[y][i])//利用gcd的方法,不停地进行辗转相除 { lld t=a[x][i]/a[y][i]; for(int k=i;k<N;k++) a[x][k]=(a[x][k]-a[y][k]*t)%MOD; swap(x,y); } if(x!=i)//奇数次交换,则D=-D'整行交换 { for(int k=0;k<N;k++) swap(a[i][k],a[x][k]); sign^=1; } } if(a[i][i]==0)//斜对角中有一个0,则结果为0 { cout<<0<<endl; return ; } else ans=ans*a[i][i]%MOD; } if(sign!=0) ans*=-1; if(ans<0) ans+=MOD; printf("%I64d\n",ans);}int main(){ int t; scanf("%d",&t); while(t--) { sign=0; scanf("%I64d%I64d",&N,&MOD); for(int i=0;i<N;i++) for(int j=0;j<N;j++) scanf("%I64d",&a[i][j]); solved(); } return 0;}
Game
总提交 : 23 测试通过 : 6
描述
lxhgww feels quite bored these days,so he invented some weird game to kill time."Counting is Easy" is undoubtedly the weirdest,it's played on a N*N chess board.You are supposed to put N rooks on the chess board,and there shouldn't be two these are in the same row or column.There are many different assignment,and it's clear that the exact number is N!,so this is not your task.In this game,there is a positive integer number on each cell of the board,an assignment's value is the product of all the numbers whose cells are occupied by rooks.To make the game more interesting,an assignment may be nagetive or possitive,the sign is decided by the number of "Z Pairs".If there is a pair of rooks in the assignment,and one is on the right-top direction(any angle is accepted) to another,this pair is a Z Pair.If there are odd number of Z Pairs,this assignment is negative,otherwise is positive.The goal of this game is to summarize all the N! assignment's value,don't forget to use minus operation while the assignment is negative.The final answer S is too large to write down,so your task is just to calculate S%P's value.
输入
The first line of input contains an integer T, indicate the number of test cases in the input.Each test case begins with two integer numbers N(where 2<=N<=200) and P(2<=P<=1000000000).The next N lines each contains N integer numbers,which describes the value of each chess board cell,all the numbers are in the range of [0,1000000000].The input is terminated by an invalid test case with N = P = 0, which should not be processed.
输出
For each test case,output one single line contains the answer S%P.
样例输入
1
2 10
4 9
2 8
样例输出
4
提示
There are two assignments(# means Rook):
*#
#*
#*
*#
First assignment's value is 2*9=18,and there are one Z-Pair,so it's negative.
Second assignment's value is 4*8=32,and there are no Z-pair,so it's positive.
So the total value S= -18 + 32 =14,and S%P=14%10=4
So the total value S= -18 + 32 =14,and S%P=14%10=4
题目来源
08年四川省省赛
- ACM矩阵行列式计算
- 复数矩阵计算行列式
- 矩阵行列式的计算
- 矩阵行列式计算
- GSL矩阵计算之行列式
- GSL计算矩阵的行列式值
- GSL计算矩阵的行列式值
- GSL矩阵计算之行列式2
- 矩阵行列式
- 行列式计算
- 行列式计算
- 行列式计算
- 计算n阶行列式和方阵逆矩阵
- c++实现4阶矩阵或行列式的计算
- 朴素的矩阵行列式计算之C++实现
- 使用vector实现矩阵,并计算N阶矩阵的行列式
- 矩阵求逆及行列式求值 - 未来再来添点更多矩阵计算功能
- 求解矩阵行列式
- 解读Java Socket非阻塞模式
- C#中的浅拷贝与深拷贝
- cloud controller和health_manager can't connection to server when starting
- Assembly动态加载DLL
- hdu1576
- ACM矩阵行列式计算
- 收藏夹
- MQTT实现消息推送
- css常见不兼容
- Linux如何把应用程序图标添加到桌面上
- ajax简单解析xml文件(复杂的解析可以通过后台程序实现,如一般处理程序)
- 关于 句柄
- C# 基于SharpZipLib 实现 文件压缩,以及解压
- Linux下获取本地IP地址--------getaddrinfo