fork(1) download
  1. #include<iostream>
  2. #include<vector>
  3. #include<map>
  4. #include<set>
  5. #include<algorithm>
  6. #include<cstdio>
  7. #include<functional>
  8. #include<cstdlib>
  9. #include<ctime>
  10. #include<cassert>
  11. #include<iomanip>
  12. #include<string>
  13. #include<cstring>
  14. #include<cctype>
  15. #include<cmath>
  16. #include<list>
  17. #include<iterator>
  18. using namespace std;
  19. typedef long long ll;
  20. #define FRN(i,a,b) for(ll i=a;i<(ll)b;i++)
  21. #define pb push_back
  22. #define mp make_pair
  23. #define INF 100000
  24. #define MOD 1000000009
  25. typedef vector<ll> vi;
  26. typedef vector<vector<ll> > vvi;
  27. typedef vector<string> vs;
  28. typedef vector<double> vd;
  29. typedef pair<ll,ll> pi;
  30. typedef map<ll,ll> mii;
  31. typedef map<string,ll> msi;
  32. typedef map<ll,string> mis;
  33. typedef vector<pair<int,int> > vp;
  34. typedef set<ll> si;
  35. typedef set<string> ss;
  36. using namespace std;
  37. #define EPS 1e-9
  38.  
  39. main(){
  40.  
  41. int n,m;
  42. cin>>n>>m;
  43. double a[n][m];
  44. for(ll i=0;i<n;i++)for(ll j=0;j<m;j++)cin>>a[i][j];
  45.  
  46. double det = 1;
  47. for (int i=0;i<n;++i) {
  48. int k = i;
  49. for (int j=i+1;j<n;++j)
  50. if (abs(a[j][i])>abs(a[k][i]))
  51. k=j;
  52. if (abs(a[k][i])<EPS) {
  53. det = 0;
  54. break;
  55. }
  56. for(int s=i;s<m;s++){
  57. double tmp=a[i][s];
  58. a[i][s]=a[k][s];
  59. a[k][s]=tmp;
  60. }
  61. if(i!=k)
  62. det =-det;
  63. det*= a[i][i];
  64. for (int j=n-1;j>=i;--j)
  65. a[i][j]/= a[i][i];
  66. for (int j=0;j<n;++j)
  67. if (j!=i&&abs(a[j][i])>EPS)
  68. for (int k=n-1;k>=i;--k)
  69. a[j][k]-= a[i][k]*a[j][i];
  70.  
  71. for(ll i=0;i<n;i++){
  72. for(ll j=0;j<m;j++)cout<<" "<<a[i][j];
  73.  
  74. cout<<endl;
  75. }
  76. cout<<endl;
  77. }
  78.  
  79. cout<<det;
  80.  
  81. }
Success #stdin #stdout 0s 3476KB
stdin
3 3
1 2 3
6 5 4
-6 4 3
stdout
  1  0.833333  0.666667
  0  1.16667  2.33333
  0  9  7

  1  0  0.0185185
  0  1  0.777778
  0  0  1.42593

  1  0  0
  0  1  0
  0  0  1

77