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 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.
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.
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.
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
#include<bits/stdc++.h>
using namespace std;
#define maxn 300010
#define LL long long
int a[][];
int main()
{
int i,j;
for(i=; i<=; i++)
for(j=; j<=; j++)
cin>>a[i][j];
a[][]=(a[][]+a[][]+a[][]+a[][]-a[][]-a[][])/;
a[][]=(a[][]+a[][]-a[][]-a[][]+a[][]+a[][])/;
a[][]=(-a[][]-a[][]+a[][]+a[][]+a[][]+a[][])/;
for(i=; i<=; i++)
{
for(j=; j<=; j++)
cout<<a[i][j]<<' ';
cout<<endl;
}
return ;
}
CodeForces-259B]Little Elephant and Magic Square的更多相关文章
- Little Elephant and Magic Square
Little Elephant loves magic squares very much. A magic square is a 3 × 3 table, each cell contains s ...
- codeforces 711B B. Chris and Magic Square(水题)
题目链接: B. Chris and Magic Square 题意: 问在那个空位子填哪个数可以使行列对角线的和相等,就先找一行或者一列算出那个数,再验证是否可行就好; AC代码: #include ...
- codeforces #369div2 B. Chris and Magic Square
题目:在网格某一处填入一个正整数,使得网格每行,每列以及两条主对角线的和都相等 题目链接:http://codeforces.com/contest/711/problem/B 分析:题目不难,找到要 ...
- 【codeforces 711B】Chris and Magic Square
[题目链接]:http://codeforces.com/contest/711/problem/B [题意] 让你在矩阵中一个空白的地方填上一个正数; 使得这个矩阵两个对角线上的和; 每一行的和,每 ...
- 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 ...
- 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 ...
- 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 ...
- Xtreme8.0 - Magic Square 水题
Xtreme8.0 - Magic Square 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/ ...
- CodeForces - 204C Little Elephant and Furik and Rubik
CodeForces - 204C Little Elephant and Furik and Rubik 个人感觉是很好的一道题 这道题乍一看我们无从下手,那我们就先想想怎么打暴力 暴力还不简单?枚 ...
随机推荐
- go 切片重组
我们已经知道切片创建的时候通常比相关数组小,例如: slice1 := make([]type, start_length, capacity) 其中 start_length 作为切片初始长度而 c ...
- C语言 文件复制
有很多人会问,学会C语言能干啥?,就只能控制台敲个数学题,做个界面都没有的贪吃蛇么? 刚开始的我,也是这样想的,但慢慢深入C语言后,我才领略到C的强大,C的万能.小到游戏破解,加解密算法,大到设备驱动 ...
- MySQL学习之路7-索引、事务、函数、存储过程、游标
索引 使用索引快速定位某列中特定值的行,不需要遍历数据表所有行. 创建索引的数据结构:BTREE and HASH. 主键也是一种索引,Primary key. show index from ord ...
- 33.2 案例:输出指定目录下的所有java文件名(包含子目录)
package day32_file_文件和目录操作; import java.io.File; public class test_输出指定目录下所有的java文件名 { public static ...
- Array(数组)对象-->sort() 方法
1.定义和用法 sort() 方法用于对数组的元素进行排序. 默认排序顺序为按字母升序. 语法: array.sort(sortfunction) 参数: sortfunction:规定排序顺序.必须 ...
- centOS7常用操作命令
大多和DOS命令差不多 文件与目录操作 命令 解析 cd /home 进入 ‘/home’ 目录 cd .. 返回上一级目录 cd ../.. 返回上两级目录 cd - 返回上次所在目录 cp fil ...
- L22 Data Augmentation数据增强
数据 img2083 链接:https://pan.baidu.com/s/1LIrSH51bUgS-TcgGuCcniw 提取码:m4vq 数据cifar102021 链接:https://pan. ...
- stand up meeting 12/3/2015
part 组员 今日工作 工作耗时/h 明日计划 工作耗时/h UI 冯晓云 初始化弹窗的弹出位置并捕捉弹窗区域内的鼠标控制事件,初步解决弹窗的拖拽功能: 6 UWP对控件的支持各种看不懂,属性 ...
- 基于RabbitMQ的Rpc框架
参考文档:https://www.cnblogs.com/ericli-ericli/p/5917018.html 参考文档:RabbitMQ 实现RPC MQ的使用场景大概包括解耦,提高峰值处理能力 ...
- [javascript] jquery的父子兄弟节点查找
jQuery.parent(expr) 找父亲节点,可以传入expr进行过滤,比如$("span").parent()或者$("span").parent(&q ...