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 分析:题目不难,找到要 ...
随机推荐
- 刷题向》关于一道奇怪的贪心(田忌赛马)BZOJ1034(NORMAL-)
这道题一看就是一道贪心,比较简单,但是越容易的题考试的时候越容易错... 没什么好说的,一遍SORT之后,直接强行田忌赛艇(滑稽脸)就好啦. 注意在对比大小的时候不仅要从前还要从后同时,不过这两个情况 ...
- module 'keras.engine.topology' has no attribute 'load_weights_from_hdf5_group_by_name'
参考: https://blog.csdn.net/heiheiya/article/details/81111932 https://blog.csdn.net/c20081052/article/ ...
- 面试题:SpringMVC的工作流程
SpringMVC是当今最主流的Web MVC框架,没有之一,要做一名合格的JavaWeb工程师,学好它势在必行! 与Struts2原理不同,SpringMVC是通过最基础最传统的servlet来实现 ...
- Browser
浏览器中关于事件的那点事儿 作者: 顽Shi 发布时间: 2014-02-01 20:22 阅读: 7830 次 推荐: 25 原文链接 [收藏] 摘要:事件在Web前端领域有很重要 ...
- hdu 4768 Flyer (异或操作的应用)
2013年长春网络赛1010题 继巴斯博弈(30分钟)签到后,有一道必过题(一眼即有思路). 思路老早就有(40分钟):倒是直到3小时后才被A掉.期间各种换代码姿态! 共享思路: unlucky st ...
- 如何在VS和CB中配置MySQL环境
这里,由于我的MySQL安装在D盘 MY SQL\MySQL Server 5.6该路径下,所以后面的路径均以D:\MY SQL\MySQL Server 5.6开头 在VS中配置MySQL环境 包含 ...
- 20169219 Nmap扫描实验
提交用 namp 对Windows 靶机,SEED靶机,Linux靶机的扫描的命令和结果进行截图 一.首先分析Linux靶机Metasploitable 扫描Metasploitableb靶机 扫描M ...
- jQuery事件(持续更新中)
方法 描述 bind() 向匹配元素附加一个或更多事件处理器 blur() 触发.或将函数绑定到指定元素的 blur 事件 change() 触发.或将函数绑定到指定元素的 change 事件 cli ...
- 百度UEditor富文本编辑器去除自动追加p标签
本篇文章还原了我在遇到这个问题时的解决过程: 找到ueditor.all.js文件,搜索 me.addInputRule(function(root){ 或者直接搜索 //进入编辑器的li要套p标签 ...
- I-team 博客全文检索 Elasticsearch 实战
一直觉得博客缺点东西,最近还是发现了,当博客慢慢多起来的时候想要找一篇之前写的博客很是麻烦,于是作为后端开发的楼主觉得自己动手丰衣足食,也就有了这次博客全文检索功能Elasticsearch实战,这里 ...