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
|
#include <bits/stdc++.h> #define Go(i , x , y) for(register int i = x; i <= y; i++) #define God(i , y , x) for(register int i = y; i >= x; i--) typedef long long LL; template < typename T > void sc(T& t) { char c = getchar(); T x = 1; t = 0; while(!isdigit(c)) {if(c == '-') x = -1; c = getchar();} while(isdigit(c)) t = t * 10 + c - '0' , c = getchar();t *= x; } template < typename T , typename... Args > void sc(T& t , Args&... args) {sc(t); sc(args...);}
const int N = 105; int n; double g[N][N] , p[N][N];
void Gauss() { Go(i , 1 , n) { int now = i; Go(j , i+1 , n) if(fabs(g[now][i]) < fabs(g[j][i])) now = j; Go(j , 1 , n+1) std::swap(g[i][j] , g[now][j]);
Go(j , i+1 , n+1) g[i][j] /= g[i][i]; g[i][i] = 1; Go(j , i+1 , n) { Go(k , i+1 , n+1) g[j][k] -= g[j][i] * g[i][k]; g[j][i] = 0; } }
God(i , n , 1) { Go(j , i+1 , n) g[i][n+1] -= g[i][j] * g[j][n+1]; g[i][n+1] /= g[i][i]; g[i][i] = 1; } } int main() { sc(n); Go(i , 1 , n+1) Go(j , 1 , n) scanf("%lf" , &p[i][j]);
Go(i , 1 , n) { Go(j , 1 , n) { double times = 2 * (p[i][j] - p[i+1][j]); g[i][j] = times; g[i][n+1] += (p[i][j] * p[i][j] - p[i+1][j] * p[i+1][j]); } }
Gauss();
Go(i , 1 , n) std::cout << std::fixed << std::setprecision(3) << g[i][n+1] << " "; std::cout << "\n"; return 0; }
|