Little Elephant and Magic Square
Little Elephant loves magic squares very much.
A magic square is a 3 × 3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15.
The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 105.
Help the Little Elephant, restore the original magic square, given the Elephant's notes.
Input
The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes.
It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 105.
Output
Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105.
It is guaranteed that there exists at least one magic square that meets the conditions.
Example
0 1 1
1 0 1
1 1 0
1 1 1
1 1 1
1 1 1
0 3 6
5 0 5
4 7 0
6 3 6
5 5 5
4 7 4 本题为数学题,列方程可得解
将第一个至第九个元素分别用字母代表,即方阵为 a b c
d e f
g h i
a,e,h为未知数 代码如下
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
int A,B,C,D,E,F,G,H,I;
scanf("%d%d%d%d%d%d%d%d%d",&A,&B,&C,&D,&E,&F,&G,&H,&I);
I = D + (F - H)/;
A = (F+H)/;
E = B+C - I;
printf("%d %d %d\n%d %d %d\n%d %d %d\n",A,B,C,D,E,F,G,H,I);
return ;
}
Little Elephant and Magic Square的更多相关文章
- CodeForces-259B]Little Elephant and Magic Square
Little Elephant loves magic squares very much. A magic square is a 3 × 3 table, each cell contains ...
- codeforces 711B B. Chris and Magic Square(水题)
题目链接: B. Chris and Magic Square 题意: 问在那个空位子填哪个数可以使行列对角线的和相等,就先找一行或者一列算出那个数,再验证是否可行就好; AC代码: #include ...
- Xtreme8.0 - Magic Square 水题
Xtreme8.0 - Magic Square 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/ ...
- Codeforces Round #369 (Div. 2) B. Chris and Magic Square 水题
B. Chris and Magic Square 题目连接: http://www.codeforces.com/contest/711/problem/B Description ZS the C ...
- Chris and Magic Square CodeForces - 711B
ZS the Coder and Chris the Baboon arrived at the entrance of Udayland. There is a n × n magic grid o ...
- B. Chris and Magic Square
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- zoj 2835 Magic Square(set)
Magic Square Time Limit: 2 Seconds Memory Limit: 65536 KB In recreational mathematics, a magic ...
- Codeforces Round #369 (Div. 2) B. Chris and Magic Square (暴力)
Chris and Magic Square 题目链接: http://codeforces.com/contest/711/problem/B Description ZS the Coder an ...
- codeforces #369div2 B. Chris and Magic Square
题目:在网格某一处填入一个正整数,使得网格每行,每列以及两条主对角线的和都相等 题目链接:http://codeforces.com/contest/711/problem/B 分析:题目不难,找到要 ...
随机推荐
- Tensorflow学习(练习)—使用inception做图像识别
import osimport tensorflow as tfimport numpy as npimport re from PIL import Imageimport matplotlib.p ...
- Python 网络爬虫 010 (高级功能) 解析 robots.txt 文件
解析 robots.txt 文件 使用的系统:Windows 10 64位 Python 语言版本:Python 2.7.10 V 使用的编程 Python 的集成开发环境:PyCharm 2016 ...
- 基于 EntityFramework 的数据库主从读写分离架构(2)- 改进配置和添加事务支持
回到目录,完整代码请查看(https://github.com/cjw0511/NDF.Infrastructure)中的目录: src\ NDF.Data.EntityFramew ...
- 多重if else和switch case的区别
int main(void) { int id; scanf_s("%d",&id); switch(id) { case 2: printf("John\n&q ...
- 数组 array 矩阵 list 数据框 dataframe
转自 : http://blog.csdn.net/u011253874/article/details/43115447 <span style="font-size:14px;& ...
- Luogu 3646 [APIO2015]巴厘岛的雕塑
初赛成绩出了,和预想的一样,一分都没挂,开心. 大佬的博客 subtask 1 ($n \leq 200$) 因为高位取$0$一定比高位取$1$优,我们考虑按照位从高到低进行检验,设$f_{i, j} ...
- SpringMVC——<mvc:annotation-driven/>
会自动注 册RequestMappingHandlerMapping .RequestMappingHandlerAdapter 与 ExceptionHandlerExceptionResolver ...
- HttpAnalyzerStdV7安装教程
相关链接:HttpAnalyzerStdV7使用教程 安装步骤: 1.解压压缩包 2.双击运行安装文件 3.根据向导提示点击Next 4.选择接受协议,点击Next 5.修改安装路 ...
- PostgreSQL 速查、备忘手册 | PostgreSQL Quick Find and Tutorial
PostgreSQL 速查.备忘手册 作者:汪嘉霖 这是一个你可能需要的一个备忘手册,此手册方便你快速查询到你需要的常见功能.有时也有一些曾经被使用过的高级功能.如无特殊说明,此手册仅适用于 Linu ...
- java实现wc功能
github项目地址:https://github.com/3216004717/ruanjiangongcheng.git 项目相关要求 基本要求 wc.exe -c file.c //返回文件 f ...