这是一道简单的模拟题
思路
- 我们先把 矩阵读入进来。
- 然后根据题意,对 数组进行模拟。由:
可得出:
- 操作完毕后,输出 数组就行了。
Code
#include<bits/stdc++.h>
using namespace std;
double a[171][171],b[171][171],w[171][171];
int main(){
int n;cin>>n;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++) cin>>w[i][j];
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
double t=w[i][j]-w[j][i];
t*=0.5,b[i][j]=t,a[i][j]=w[i][j]-b[i][j],b[j][i]=-t,a[j][i]=w[j][i]-b[j][i];
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++) printf("%.8lf ",a[i][j]);
cout<<endl;
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++) printf("%.8lf ",b[i][j]);
cout<<endl;
}
}