想骂人
2024-07-29 14:46:46
发布于:浙江
16阅读
0回复
0点赞
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include<iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
using namespace std;
const int N = 100;
const double eps = 1e-6;
double a[N][N];
int n;
bool gauss() {
int r = 0;
for (int c = 0; c < n; c++) {
int t = r;
for (int i = r; i < n; i++)
if (fabs(a[i][c]) > fabs(a[t][c]))
t = i;
if (fabs(a[t][c]) < eps) continue;
for (int i = c; i < n + 1; i++) swap(a[t][i], a[r][i]);
for (int i = n; i >= c; i--) a[r][i] /= a[r][c];
for (int i = r + 1; i < n; i++)
if (fabs(a[i][c]) > eps)
for (int j = n; j >= c; j--)
a[i][j] -= a[r][j] * a[i][c];
r++;
}
if (r < n) return 1;
for (int i = n - 1; i >= 0; i--) for (int j = i + 1; j < n; j++) a[i][n] -= a[j][n] * a[i][j];
return 0;
}
int main() {
cin >> n;
for (int i = 0; i < n; i++)
for (int j = 0; j < n + 1; j++)
cin >> a[i][j];
bool t = gauss();
if (t == 0) for (int i = 0; i < n; i++) printf("x%d=%.2lf\n",i+1 ,a[i][n]);
else puts("No Solution");
return 0;
}
不是我就很疑惑,acgo数据这么水的吗,我数组开60都能过然后根本没有考虑无解和无数解就ac了
服了
这里空空如也
有帮助,赞一个