2017CCPC湘潭A题Determinant
来源:互联网 发布:mysql备份数据库 编辑:程序博客网 时间:2024/06/05 10:35
传送门:http://202.197.224.59/OnlineJudge2/index.php/Contest/read_problem/cid/43/pid/1260
Determinant
Bobo learned the definition of determinant
Bobo has an
Input
The input contains zero or more test cases and is terminated by end-of-file. For each test case:
The first line contains an integer
2≤n≤200 0≤Bi,j<109+7 - The sum of
n does not exceed2000 .
Output
For each case, output
Sample Input
22 031 2 06 3 1
Sample Output
0 22 1 999999998
Note
For the second sample,官方题解:随机n个数把矩阵补全成n×n的。
那么就是要算伴随矩阵的第一行,也就是逆矩阵的第一列,高斯消元即可。
然后以下是Q巨的写法:
#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<ctime>#include<iostream>#include<algorithm>using namespace std;const int MAXN=205;const int Mod=1000000007;int a[MAXN][MAXN],b[MAXN][MAXN];int get_rand(int x)//[0,x){ int t=1; while((1<<t)<x)t++; int res=x; while(res>=x) { res=0; for(int i=0;i<t;i++) res|=(rand()%2)<<i; } return res;}int fp(int a,int k){ int res=1; while(k) { if(k&1)res=1LL*res*a%Mod; a=1LL*a*a%Mod; k>>=1; } return res;}void solve(int n){ for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) b[i][j]=(i==j); int det=1; for(int i=1;i<=n;i++) { int t=i; for(int k=i;k<=n;k++) if(a[k][i])t=k; if(t!=i)det*=-1; for(int j=1;j<=n;j++) { swap(a[i][j],a[t][j]); swap(b[i][j],b[t][j]); } det=1LL*a[i][i]*det%Mod; int inv=fp(a[i][i],Mod-2); for(int j=1;j<=n;j++) { a[i][j]=1LL*inv*a[i][j]%Mod; b[i][j]=1LL*inv*b[i][j]%Mod; } for(int k=1;k<=n;k++) { if(k==i)continue; int tmp=a[k][i]; for(int j=1;j<=n;j++) { a[k][j]=(a[k][j]-1LL*a[i][j]*tmp%Mod+Mod)%Mod; b[k][j]=(b[k][j]-1LL*b[i][j]*tmp%Mod+Mod)%Mod; } } } det=(det+Mod)%Mod; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) b[i][j]=1LL*det*b[i][j]%Mod;}int main(){ srand(time(NULL)); int n; while(scanf("%d",&n)!=EOF) { for(int j=1;j<=n;j++) a[1][j]=2; for(int i=2;i<=n;i++) for(int j=1;j<=n;j++) scanf("%d",&a[i][j]); solve(n); for(int i=1;i<=n;i++) printf("%d%c",(i&1 ? b[i][1] : (Mod-b[i][1])%Mod)," \n"[i==n]); } return 0;}
- 2017CCPC湘潭A题Determinant
- 湘潭CCPC A题
- 湘潭2017 ccpc中南地区邀请赛 Determinant 高斯约当求逆矩阵
- 2017湘潭赛a题
- 2017 ccpc 湘潭邀请赛 H highway
- 2017CCPC中南地区赛暨湘潭大学邀请赛总结
- CCPC 2015 A题
- 2015 CCPC A题 【水题】
- 15年湘潭邀请赛 A题 Coins
- 湘潭邀请赛 A题 矩阵快速幂
- xtu 1260 Determinant [2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛(湖南) A题]
- 2017ccpc全国邀请赛(湖南湘潭) E. Partial Sum(前缀和)
- 2017ccpc全国邀请赛(湖南湘潭) H. Highway (最大生成树)(树的直径)
- 2017ccpc全国邀请赛(湖南湘潭) H. Highway XTOJ 1267 【树的直径】
- Determinant
- 湘潭邀请赛A
- 2017 CCPC 秦皇岛 A:Balloon Robot
- 2017ccpc 秦皇岛-A Balloon Robot
- 校园二手物品交易系统
- 杭电1042
- python 处理xml文件
- 单点登录原理与简单实现
- Swift--05可选类型
- 2017CCPC湘潭A题Determinant
- Spring对注解(Annotation)处理源码分析2——解析和注入注解配置的资源
- 用这个,3Glasses就能玩Oculus 平台游戏了
- PostgreSQL数据库创建、删除方法
- PeerConnection分析之总类图
- pl/sql程序块
- 网络编程实战
- The reference to entity "characterEncoding" must end with the ';' delimiter.
- ajax请求数据和处理数据的案例展示