题解:CF393B Three matrices

原文:https://www.luogu.com.cn/article/xyoaxhpt 点个赞吧!


这是一道简单的模拟题

思路

  1. 我们先把 $W$ 矩阵读入进来。
  2. 然后根据题意,对 $W,A,B$ 数组进行模拟。由:
  • $ A_{i,j}=A_{j,i} $

  • $ B_{i,j}=-B_{j,i} $

  • $ W_{i,j}=A_{i,j}+B_{i,j} $

可得出:

  • $ A_{i,j}=A_{j,i} $

  • $ B_{i,j}=-B_{j,i} $

  • $ W_{i,j}-W_{j,i}=B_{i,j} \times 2 $

  1. 操作完毕后,输出 $A,B$ 数组就行了。

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#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;
}
}

题解:CF393B Three matrices
https://cjy20121019.github.io/2026/02/16/题解:CF393B Three matrices/
作者
CJY_Holmes
发布于
2026年2月16日
更新于
2026年2月16日
许可协议