1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
| #include<bits/stdc++.h> #define fo(i,j,k) for(int i=j;i<=k;++i) using namespace std;
const int MAXN=105; int n;
struct juzhen{ juzhen(int han,int lin){ h=han,l=lin; memset(v,0,sizeof(v)); } juzhen(){ memset(v,0,sizeof(v)); } void resize(int han,int lin){ h=han,l=lin; memset(v,0,sizeof(v)); } void cleanForPow(void){ memset(v,0,sizeof(v)); int p=min(h,l); for(int i=1;i<=p;++i){ v[i][i]=1; } } friend juzhen operator *(juzhen a,juzhen b){ juzhen c(a.h,b.l); if(a.l!=b.h)return c; for(int i=1;i<=a.h;++i){ for(int j=1;j<=b.l;++j){ long long s=0; for(int k=1;k<=a.l;++k){ s=s+(a.v[i][k]*b.v[k][j]); } c.v[i][j]=s; } } return c; } friend juzhen operator +(juzhen a,juzhen b){ int ha=max(a.h,b.h); int li=max(a.l,b.l); juzhen c(ha,li); fo(i,1,ha){ fo(j,1,li){ c.v[i][j]=a.v[i][j]+b.v[i][j]; } } } juzhen pow(int k){ juzhen res=*this; juzhen ret(h,l); ret.cleanForPow(); while(k){ if(k&1){ ret=ret*res; } res=res*res; k>>=1; } return ret; } void setV(long long t[MAXN][MAXN]){ for(int i=1;i<=h;++i){ for(int j=1;j<=l;++j){ v[i][j]=t[i][j]; } } } void print(void){ fo(i,1,h){ fo(j,1,l){ cout<<v[i][j]<<' '; } cout<<'\n'; } } void gsxy(void){ for(int i=1;i<=n;++i){ int mark=0; double tmp=0; for(int j=i;j<=n;++j){ if(fabs(v[j][i])>tmp){ mark=j; tmp=fabs(v[j][i]); } } for(int j=i;j<=n+1;j++){ swap(v[i][j],v[mark][j]); } for(int j=1;j<=n;++j){ if(i==j)continue; double rate=v[j][i]/v[i][i]; for(int k=i;k<=n+1;++k){ v[j][k]-=v[i][k]*rate; } } } } double v[MAXN][MAXN]; int h,l; };
int main(void){ cin>>n; juzhen a(n,n+1); for(int i=1;i<=n;++i){ for(int j=1;j<=n+1;++j){ cin>>a.v[i][j]; } } a.gsxy(); for(int i=1;i<=n;++i){ if(fabs(a.v[i][n+1]/a.v[i][i]<=1e-8))printf("0 "); else printf("%0.lf ",a.v[i][n+1]/a.v[i][i]); } return 0; }
|