intgauss(){ int c,r; //行,列 for (c = 0, r = 0; c < n; c ++){ int t = r;//找这一列绝对值最大的行 for (int i = r; i < n; i ++ ) if (fabs(a[i][c]) > fabs(a[t][c])) t = i;
if (fabs(a[t][c]) < eps ) continue;//如果最大值是0就跳过
for (int i = c; i < n + 1; i ++ ) swap(a[t][i],a[r][i]);//换到最上面那一行 for (int i = n; i >= c; i --) a[r][i] /= a[r][c];//每行第一个数变成1(除上一个数),倒着操作才能保证正确,如果正序,a[r][c]一直是1,对后面没有影响 for (int i = r + 1; i < n; i ++ ) if (fabs(a[i][c]) > eps) for (int j = n; j >= c; j -- ) a[i][j] -= a[r][j]* a[i][c];//(加减一行的整数倍,如此操作可以让该列的数变成0)同理,如果正序更新,a[i][c]会发生变化。 r++; } if (r < n) { for (int i = r; i < n; i ++) if (fabs(a[i][n] < eps)) return2;//b[i] = 0,那么有无穷组解 return1;//0 == !0 ,无解 } for (int i = n - 1; i >= 0 ; i --){ for (int j = i + 1; j< n; j ++ ) a[i][n] -= a[j][n]*a[i][j];//减去其他解*系数得到该位置上的解 } return0; }
intmain(){ cin >> n; for (int i = 0; i< n; i ++) for ( int j = 0 ; j < n + 1; j ++) cin >> a[i][j]; int ans = gauss(); if (ans == 0) { for (int i = 0; i< n; i ++) printf("%.2lf\n",a[i][n]); }elseif (ans == 2) puts("Infinite group solutions"); elseputs("No solution"); }
intgauss(){ int r ,c; for (c = r = 0; c < n; c ++ ){ int t = r; for (int i = r ; i < n; i ++ ) if (a[i][c]) { t = i; break; } if (!a[t][c]) continue; for (int i =c ; i<= n; i ++ ) swap(a[t][i],a[r][i]); for (int i = r + 1; i < n; i ++ ) if (a[i][c]) for (int j = n; j >= c; j-- ) a[i][j] ^= a[r][j]; r++; } if (r < n) { for (int i = r ; i < n; i ++) if (!a[i][n]) return2; return1; } for (int i = n - 1 ; i>= 0; i --) for ( int j = i + 1; j< n;j ++ ) a[i][n] ^= a[j][n] * a[i][j]; return0; }
intmain(){ cin >> n; for (int i = 0 ;i < n ; i++) for (int j = 0 ; j< n + 1; j ++ ) cin >> a[i][j]; int t = gauss(); if (t == 2) puts("Multiple sets of solutions"); elseif (t == 1) puts("No solution") ; elsefor ( int i = 0 ; i< n ;i ++ ) cout << a[i][n] << endl; }
#include<iostream> #include<algorithm> #include<cstring> #include<cmath> usingnamespace std; typedeflonglong ll; constint N = 1e5 + 7,mod = 1e9 +7; int n; int fact[N],infact[N]; intqmi(int a,int b,int p){ ll res = 1; while (b){ if (b & 1) res = res * a % p; a = (ll)a * a % p; b >>= 1; } return res; }
intmain(){ cin >> n; fact[0] = infact[0] = 1; for (int i =1 ; i < N; i ++ ){ fact[i] = (ll)fact[i-1]*i%mod; infact[i] = (ll)infact[i-1] % mod * qmi(i,mod - 2,mod) % mod; } while (n --){ int a,b; cin >> a >> b; cout <<(ll) fact[a] % mod* infact[a-b]%mod * infact[b] % mod<<endl; } }