题目链接:Codeforces 393B Three matrices
题目大意:给出一个矩阵w,要求构造出两个矩阵a,b;要求a是对称矩阵a[i][j] = a[j][i],b是负对称矩阵b[i][j] = -b[j][i],并且a[i][j] + b[i][j] = w[i][j]。
解题思路:a[i][j] + b[i][j] = w[i][j]; a[j][i] + b[j][i] = a[i][j] - b[i][j] = w[j][i];两式子相加相减除2就分别是a[i][j]和b[i][j].
#include <stdio.h>
#include <string.h>
#include <math.h>
const int N = 200;
int n;
double s[N][N], a[N][N], b[N][N];
inline double cal(double x) {
if (fabs(x) < 1e-9) return 0;
return x;
}
int main () {
scanf("%d", &n);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) scanf("%lf", &s[i][j]);
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
a[i][j] = a[j][i] = (s[i][j] + s[j][i]) / 2;
double t = (s[i][j] - s[j][i]) / 2;
b[i][j] = t; b[j][i] = -t;
}
}
for (int i = 0; i < n; i++) {
printf("%.8lf", cal(a[i][0]));
for (int j = 1; j < n; j++) printf(" %.8lf", cal(a[i][j]));
printf("\n");
}
for (int i = 0; i < n; i++) {
printf("%.8lf", cal(b[i][0]));
for (int j = 1; j < n; j++) printf(" %.8lf", cal(b[i][j]));
printf("\n");
}
return 0;
}
分享到:
相关推荐
Codeforces - 1107B. Digital root & 1107C. Brutality(规律 & 贪心)Codeforces - 1107B.
Codeforces 1105B - Zuhair and Strings 测试点37个(全)
Codeforces 题库 101-200 共~500题 codeforces.com版权所有。 程序可提交至该网站评测。
Codeforces 题库 001-100 共~500题 codeforces.com版权所有。 程序可提交至该网站评测。
codeforces编程网站预测分数插件
使用于Google Chrome的Codeforces Enhancer 1.1.2插件安装包。 版本:codeforces enhancer 1.1.2 使用浏览器:Google Chrome
Codeforces 185A - Plant 全测试点49个
codeforces 19 E Fairy 一道比较难的题目的解题报告 推荐阅读
Codeforces global round 10 codes
Codeforces round 678 division 2 codes
Some of the Codeforces problems codes
lucifer1004大佬的博客cf上分攻略故里大佬的githubcf思维题刷题数:44- (1421)codeforces 676 div2 A,B done
Codeforces round 678 D2_Codeforces_源码
一个Codeforces、牛客竞赛、AtCoder平台的编程竞赛查询插件,ACMer必备.zip
打codeforces的神器
codeforces-js Codeforces JS
接受串子-接受字符串相等-接受Codeforces回合#684(Div.2) 2/6 1440A-购买琴弦-接受1440B -中位数的总和-已接受1440C1-二进制表(简易版)-已接受1440C2-二进制表(硬版)-已接受 Codeforces回合#683(分区2) 1/...
Codeforces Round #723 (Div. 2).md
使用 C# + WPF 开发 --- 还在发愁打了那么多场比赛都没有进入首页么? 还在为了前 5 的 hacker 名额阅读千份代码么? 是的,你没有看错! 这是一个 Edu & Div.3 轮 Open hacking 错误代码自动查找器!...
PDF-CodeForces问题 PDF文件中的CodeForces问题 利用CodeForces提取在这个库中的文件 ,文件夹名代表来自CodeForces网址contests`的ID,每个文件夹包含比赛的问题。 有关CodeForces竞赛的疯狂事实 CodeForces上有937...