bzoj 2107 Spoj2832 Find The Determinant III
来源:互联网 发布:淘宝虚拟类目直通车 编辑:程序博客网 时间:2024/05/22 12:34
这题刚开始的第一想法是求每一个元素的逆元,然后直接化简行列式为上三角求行列式的值,但是不一定每个元素都与p互质。所以,这条路就基本走不通了。
后来看了题解,才发现原来可以用辗转相消的方法来消元求行列式。
伪代码:
代码:
#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>#define LL long long#define maxn 320using namespace std;int n;LL p;LL ans=1;LL deter[maxn][maxn];int main(){while (~scanf("%d%lld", &n, &p)){ans=1;for (int i=0;i<n;i++)for (int j=0;j<n;j++){scanf("%lld",&deter[i][j]);deter[i][j]=deter[i][j]%p;}for (int i=0;i<n;i++){if (!deter[i][i]){bool flag=0;for (int j=i+1;j<n;j++)if (deter[j][i]){flag=1;for (int k=i;k<n;k++)swap(deter[i][k],deter[j][k]);ans=-ans;break;}if (!flag){puts("0");return 0;}}for (int j=i+1;j<n;j++)while (deter[j][i]){LL t=deter[i][i]/deter[j][i];for (int k=i;k<n;k++){deter[i][k]=(deter[i][k]-t*deter[j][k])%p;swap(deter[j][k],deter[i][k]);}ans=-ans;}ans=ans*deter[i][i]%p;}ans=(ans+p)%p;printf("%lld\n",ans);}return 0;}
0 0
- bzoj 2107 Spoj2832 Find The Determinant III
- SPOJ2832--- Find The Determinant III
- Find The Determinant III SPOJ
- SPOJ 2832 DETER3 - Find The Determinant III(矩阵行列式)
- SPOJ-Find The Determinant III(矩阵行列式)
- SPOJ (不知道题号是多少) DETER3 - Find The Determinant III
- SPOJ DETER3 Find The Determinant III(求行列式的秩、高斯消元)
- bzoj 4689: Find the Outlier
- Determinant
- HDU 2827 The Evaluation of Determinant 题解
- [BZOJ]4689: Find the Outlier 高斯消元
- BZOJ 4689 Find the Outlier 高斯消元
- bzoj 4994: [Usaco2017 Feb]Why Did the Cow Cross the Road III
- bzoj 4997: [Usaco2017 Feb]Why Did the Cow Cross the Road III
- bzoj 4991: [Usaco2017 Feb]Why Did the Cow Cross the Road III
- bzoj 4991 [Usaco2017 Feb]Why Did the Cow Cross the Road III 树状数组套Treap
- [BZOJ]4991: [Usaco2017 Feb]Why Did the Cow Cross the Road III CDQ分治+树状数组
- 集训队专题(8)1008 The Evaluation of Determinant
- APK打包过程分析
- POJ 3268Silver Cow Party
- 阶乘尾部包含n个0的最小数字
- 多线程集合队列等等
- 让EFCore更疯狂些的扩展类库(一):通过json文件配置sql语句
- bzoj 2107 Spoj2832 Find The Determinant III
- [转载]Word文档如何发CSDN博客
- requests 库的另类用法(stream)
- Java 开源博客 Solo 1.8.0 发布 - 改进文件上传
- 由于清屏命令,导致调用函数前的语句无法打印
- BZOJ 1057: [ZJOI2007]棋盘制作 单调栈裸题
- 写了一个从oracle导数据到hbase的多线程java程序,只要创建一个实体加上注解基本就可以导数据了
- LCD灯
- [转载]ANSYS12.0安装教程