标签:pac inf ace BMI names make sub c++ mit
#include <bits/stdc++.h> #define ios ios::sync_with_stdio(false) #define ll long long #define mp make_pair #define ull unsigned long long using namespace std; const int inf = 0x3f3f3f3f; const ll INF = 0x3f3f3f3f3f3f3f3f; const int mod = 1e9 + 7; const int N = 105; double ma[N][N];//增广矩阵 double x[N]; int Gauss(int n) { int max_r;//当前这列绝对值最大的行 int col = 1;//当前处理的列 double temp; for(int i = 1; i <= n; i++){ max_r = i; for(int j = i+1; j <= n; j++){ if(fabs(ma[i][j]) > fabs(ma[max_r][j])) max_r = j; } for(int j = 1; j <= n+1; j++) swap(ma[i][j],ma[max_r][j]); if(!ma[i][i]) return -1; for(int j = 1; j <= n; j++){ if(j != i){ double t = ma[j][i]/ma[i][i]; for(int k = i+1; k <= n+1; k++){ ma[j][k] -= ma[i][k]*t; } } } } for(int i = 1; i <= n; i++){ x[i] = ma[i][n+1]/ma[i][i]; } return 0; } int main(){ int n; cin >> n; for(int i = 1;i <= n;i++){ for(int j = 1;j <= n+1;j++){ cin >> ma[i][j]; } } int op = Gauss(n); if(op == -1) printf("No Solution\n"); else{ for(int i = 1; i <= n; i++) printf("%.2lf\n",x[i]); } return 0; }
模板题https://www.luogu.org/problem/P3389
标签:pac inf ace BMI names make sub c++ mit
原文地址:https://www.cnblogs.com/philo-zhou/p/11385640.html