gghack_Nythix @ 2024-08-04 09:01:02
rt,请指出我源代码的问题,不要直接发给我你的AC代码。
#include<bits/stdc++.h>
using namespace std;
int n;
double a[1005][1005];
double check[1005];
void Consumption() {
// int row = 1;
for(int i = 1;i <= n;++i) {
for(int j = i + 1;j <= n;++j) {
if(fabs(a[j][i]) > 1e-2) {for(int k = 1;k <= n + 1;++k) swap(a[i][k],a[j][k]); break;}
}
if(fabs(a[i][i]) < 1e-12) continue;
for(int j = 1;j <= n;++j) {
if(j == i) continue;
double rt = a[j][i] / a[i][i];
for(int k = i;k <= n + 1;++k) a[j][k] -= a[i][k] * rt;
}
// ++row;
}
bool flag2 = 0;
for(int i = 1;i <= n;++i){
bool flag = 0;
for(int j = 1;j <= n;++j){
if(fabs(a[i][j]) > 1e-12) flag = 1;
}
if(!flag){
flag2 = 1;
if(fabs(a[i][n + 1]) > 1e-12) return cout << "-1\n",void();
}
}
if(flag2) {
return cout << "0\n",void();
}
for(int i = 1;i <= n;++i) cout << "x" << i << "=" << fixed << setprecision(2) << double(a[i][n + 1] / a[i][i]) << '\n';
return ;
}
signed main(){
cin >> n;
for(int i = 1;i <= n;++i) for(int j = 1;j <= n + 1;++j) cin >> a[i][j];
return Consumption(),0;
}
by gghack_Nythix @ 2024-10-14 21:07:05
@2024ing 感谢,但是我A了。
by 2024ing @ 2024-10-14 21:43:27
@gghack_Nythix 那就好,不客气