存份模板(模板洛咕$P3389$)
1 #include2 3 int n; 4 5 double a[200][200], b[200]; 6 7 int main() 8 { 9 scanf("%d", &n);10 for (int i = 1; i <= n; i++)11 {12 for (int j = 1; j <= n; j++)13 std::cin >> a[i][j];14 std::cin >> b[i];15 } 16 17 for (int i = 1; i <= n; i++)18 {19 for (int j = i; j <= n; j++)20 {21 if (fabs(a[j][i]) > 1e-8)22 {23 for (int k = 1; k <= n; k++)24 std::swap(a[i][k], a[j][k]);25 std::swap(b[i], b[j]);26 }27 }28 if(fabs(a[i][i]) < 1e-8)29 {30 puts("No Solution");31 return 0;32 }33 for (int j = 1; j <= n; j++)34 {35 if (i == j)36 continue;37 double rate = a[j][i] / a[i][i];38 for (int k = i; k <= n; k++)39 a[j][k] -= a[i][k] * rate;40 b[j] -= b[i] * rate;41 }42 }43 for (int i = 1; i <= n; i++)44 printf("%.2f\n", b[i] / a[i][i]);45 return 0;46 }