#include <iostream>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <climits>
#include <random>
#include <bitset>
#include <unordered_map>
#define orz %
#define ll long long
#define juruo Optimist_Skm
#define mid ((l + r) >> 1)
#define pii std::pair<int, int>
#define fi first
#define se second
#define eb emplace_back
#define pb push_back
#define m_p std::make_pair
#define pq std::priority_queue<int>
#define pq_min std::priority_queue<int, std::vector<int>, std::greater<int> >
#define open(x) freopen(#x".in", "r", stdin);freopen(#x".out", "w", stdout);
#define test(x) cout << "Test: " << x << '\n'
#define close fclose(stdin);fclose(stdout);
#define ull unsigned long long
#define debug(); printf("qwq\n");
namespace Fast_Skm {
template <typename T>
inline void read(T &x) {
register T s = 0, w = 1;
char c = getchar();
while(!isdigit(c)) {
if(c == '-') w = -1;
c = getchar();
}
while(isdigit(c))
s = (s << 1) + (s << 3) + (c & 0xcf), c = getchar();
x = s * w;
return ;
}
template <typename T, typename... Arp>
inline void read(T &x, Arp &...arp) {
read(x), read(arp...);
return ;
}
template <typename T>
inline void write(T x) {
if(x < 0) x = -x, putchar('-');
register int p = 0;
static char s[100];
do {
s[++p] = x orz 10 + '0';
x /= 10;
} while (x);
while(p) putchar(s[p--]);
putchar(' ');
}
template <typename T, typename... Arp>
inline void write(T &x, Arp &...arp) {
write(x), write(arp...);
return ;
}
template <typename S, typename T>
inline void smax(S &x, T y) {
x = (x > y) ? x : y;
}
template <typename S, typename T>
inline void smin(S &x, T y) {
x = (x < y) ? x : y;
}
inline void quit() {
exit(0);
return ;
}
inline ll quick_pow(ll a, ll b, ll P) {
register ll ans = 1;
while(b >= 1) {
if(b & 1) {
ans = ans * a % P;
}
a = a * a % P;
b >>= 1;
}
return ans;
}
template <typename T>
inline T exgcd(T a, T b, T &x, T &y) {
if(b == 0) {
x = 1; y = 0;
return a;
}
int gcd = exgcd(b, a % b, x, y);
int tmp = y;
y = x - a / b * y;
x = tmp;
return gcd;
}
} using namespace Fast_Skm;
const int N = 105;
double eps = 1e-7;
int n;
double a[N][N];
inline int gauss(int n, int m) { //n元,m个等式
int c = 0;//当前主元数
for (int i = 1; i <= n; ++i) { //枚举第i元(列)
bool f = 0;
for (int j = c + 1; j <= m; ++j) { //枚举第j个等式(行)
if (fabs(a[j][i]) > eps) { //寻找系数不为0的行
++c, f = 1;
std::swap(a[j], a[c]);//交换
break;
}
}
if (!f) continue;
double p = a[c][i];
for (int j = 1; j <= n + 1; ++j) { //系数化为一
a[c][j] = a[c][j] * 1.0 / p;
}
for (int j = 1; j <= m; ++j) { //加减消元
if (j != c && fabs(a[j][i]) > eps) {
double q = a[j][i];
for (int k = i; k <= n + 1; ++k) {
a[j][k] -= a[c][k] * q;
}
}
}
}
for (int i = c + 1; i <= m; ++i)
if (fabs(a[i][n + 1]) > eps) return -1;//无解
if (c == n) return 0;//唯一解
return 1;//无穷多解
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
read(n);
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n + 1; ++j) {
scanf("%lf", &a[i][j]);
}
}
if (!gauss(n, n)) {
for (int i = 1; i <= n; ++i) {
printf("%.2lf\n", a[i][n + 1]);
}
} else {
printf("No Solution");
}
return 0;
}
标签:std,return,int,inline,include,高斯消,define
From: https://www.cnblogs.com/optimist-skm/p/18313690