fork download
  1. #include <cmath>
  2. #include <cstring>
  3. #include <cstdio>
  4. #include <cstdlib>
  5. #include <iostream>
  6. #include <fstream>
  7. #include <algorithm>
  8. #include <queue>
  9.  
  10. #define rep(i, l, r) for(int i = l; i <= r; i++)
  11. #define down(i, l, r) for(int i = l; i >= r; i--)
  12. #define MS 19
  13. #define MAX 1037471823
  14. #define Q 103
  15.  
  16. using namespace std;
  17.  
  18. int n;
  19. double b[MS][MS], k[MS][MS], a, x[MS];
  20.  
  21. int main()
  22. {
  23. scanf("%d", &n);
  24. rep(i, 1, n+1) rep(j, 1, n) scanf("%lf", &b[i][j]);
  25. rep(i, 1, n) rep(j, 1, n) k[i][j] = b[i][j] - b[i+1][j];
  26. rep(i, 1, n) rep(j, 1, n) k[i][0] += b[i][j] * b[i][j] - b[i+1][j] * b[i+1][j];
  27. rep(i, 1, n) k[i][0] /= 2;
  28. rep(i, 1, n)
  29. {
  30. rep(j, i+1, n)
  31. {
  32. a = k[j][i] / k[i][i];
  33. rep(o, 0, n) k[j][o] -= k[i][o] * a;
  34. }
  35. }
  36. down(i, n, 1)
  37. {
  38. x[i] = k[i][0] / k[i][i];
  39. rep(j, 1, i-1) k[j][0] -= k[j][i] * x[i];
  40. }
  41. rep(i, 1, n-1) printf("%.3f ", x[i]); printf("%.3f", x[n]);
  42. return 0;
  43. }
  44.  
Success #stdin #stdout 0s 3348KB
stdin
2
0.0 0.0
-1.0 1.0
1.0 0.0
stdout
0.500 1.500