标签:
1 #include<bits/stdc++.h> 2 using namespace std; 3 int n; 4 double res[111],G[111][111]; 5 void guess(int ii) 6 { 7 int i,j; 8 double first=G[ii][ii],first1; 9 for(i=ii+1;i<=n;i++) 10 { 11 first1=-G[i][ii]; 12 for(j=ii;j<=n+1;j++)G[i][j]+=((G[ii][j]*first1)/first); 13 } 14 } 15 double r_guess(int ii) 16 { 17 int i=ii; 18 double sum=G[ii][n+1]; 19 while(i<=n)i++,sum-=(G[ii][i]*res[i]); 20 return sum/G[ii][ii]; 21 } 22 int main() 23 { 24 int i,j; 25 scanf("%d",&n); 26 for(i=1;i<=n;i++) 27 { 28 for(j=1;j<=n+1;j++)scanf("%lf",&G[i][j]); 29 } 30 for(i=1;i<n;i++)guess(i); 31 for(i=n;i>=1;i--)res[i]=r_guess(i); 32 for(i=1;i<=n;i++)printf("%d ",(int)floor(res[i]+0.5)); 33 return 0; 34 }
标签:
原文地址:http://www.cnblogs.com/wjcwjc/p/4998244.html