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 分析:题目不难,找到要 ... 
随机推荐
- Redis01 Redis服务端环境搭建
			1 前提准备 下载 VM centos6 安装包,安装好虚拟系统 2 安装远程连接工具 工具获取 2.1 SecureCRT.Xshell 连接远程服务器 2.2 WinSCP 向远程服务器发送文件 ... 
- Java 基于quartz实现定时 之一(注解方式配置)
			需要在项目里,导入quartz.jar package cn.zr.pringmvctest.trigger; import org.springframework.context.annotatio ... 
- lucene 第二天
			Lucene/Solr 第二天 1. 课程计划 Lucene的Field Lucene的索引库维护 lucene的查询 a) Query子对象 b) QueryParser Lucene相关度排序 ... 
- CF1073F Choosing Two Paths
			发现从顶点入手不太方便,我们从这个“公共部分最长”开始考虑问题,因为要求这一条公共部分的链最长,可以联想到树的直径,那么本题就是要求一条类似于直径的东西使两个端点除了直径这一条链之外还有不少于两个的儿 ... 
- Luogu 3066 [USACO12DEC]逃跑的BarnRunning Away From…
			好像是某CF的题,不记得…… 很套路的题,但是觉得可以做一下笔记. 倍增 + 差分. 有一个比较简单的思路就是每一个点$x$向上走一走,直到走到一个点$y$使总路程恰好不超过超过了$L$,然后把$(x ... 
- hdu 4681 String(转载)
			#include <stdio.h> #include <string.h> #include <algorithm> #include <iostream& ... 
- System.Web.UI.Page事件执行顺序
			#region OnPreInit 第一步(显式重写,文章下面有隐式重写) protected override void OnPreInit(EventArgs e) { //检查 IsPostBa ... 
- HandleErrorAttribute只能处理httpStatusCode为500的异常(服务器异常)
			HandleErrorAttribute源代码: [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited ... 
- Linq学习<三> linq to entity
			之前一直用sql选择出数据放在一个集合中,然后再用Linq或者lambda去操作数据,今天学了Linq to entity 才知道原来linq产生是为了Entity.也就是EDM(实体数据模型) 关于 ... 
- 二度xml<一>
			又一次学习Xml,之前差不多都忘了,为了下半年的面试,为了工作重头来过....... 其实我觉得直接上代码来的更实际点,理论的东西,我们随便找点书看看就行. 下面的代码是为了打印出一个xml文件 xm ... 
