include iostream include vector include cmath using namespace std void

  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
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
void Getminor(vector <vector<double> > a, vector <vector<double> > &b, int x, int y, int size)
{
int xCount = 0, yCount = 0;
for (int i = 0; i < size; i++)
{
if (i != x)
{
yCount = 0;
for (int j = 0; j < size; j++)
{
if (j != y)
{
b[xCount][yCount] = a[i][j];
yCount++;
}
}
xCount++;
}
}
}
double FindDeterminant(vector <vector<double> > a, int size)
{
// останавливаем рекурсию, если матрица
// состоит из одного элемента
if (size == 1)
{
return a[0][0];
}
else
{
double det = 0.0;
vector <vector<double> > minor(size - 1, vector <double> (size -1));
for (int i = 0; i < size; i++)
{
Getminor(a, minor, 0, i, size);
// Рекурсия
det += (((i % 2) == 0) ? 1 : -1) * a[0][i] * FindDeterminant(minor, size - 1);
}
return det;
}
}
double FindAdditionalDeterminant(vector <vector<double> > a, vector <double> b, int size, int j) {
for (int i = 0; i < size; i++){
a[i][j] = b[i];
}
double determinant = FindDeterminant(a, size);
return determinant;
}
int main()
{
freopen("input.txt", "r", stdin);
int n;
cin >> n;
vector <vector<double> > a(n, vector <double> (n));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
cin >>a[i][j];
}
}
vector <double> b(n);
for (int i = 0; i < n; ++i) {
cin >>b[i];
}
cout << "n:" << n << endl;
cout << "matr a:" << endl;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
cout << a[i][j] <<" ";
cout << endl;
}
cout << "vect b:" << endl;
for (int i; i < n; i++) {
cout << b[i] << endl;
}
cout << endl;
// находим определитель матрицы
double determinant = FindDeterminant(a, n);
vector <double> det(n);
vector <double> answers(n);
for (int i = 0; i < n; ++i) {
det[i] = FindAdditionalDeterminant(a, b, n, i);
answers[i] = det[i] / determinant;
}
for (int i; i < n; i++) {
cout << answers[i] << endl;
}
}