C. Magic Odd Square

time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output

Find an n × n matrix with different numbers from 1 to n2, so the sum in each row, column and both main diagonals are odd.

Input

The only line contains odd integer n (1 ≤ n ≤ 49).

Output

Print n lines with n integers. All the integers should be different and from 1 to n2. The sum in each row, column and both main diagonals should be odd.

Examples
Input
1
Output
1
Input
3
Output
2 1 4
3 5 7
6 9 8
题目连接:http://codeforces.com/problemset/problem/710/C

题意:n*n的矩阵内填入1~n*n使得行,列,对角线的和为奇数(n为奇数)。
思路:n阶幻方(行,列,对角线的和相等)也符合这种情况。
传送门:n阶幻方代码:
 #include<iostream>
#include<cstdio>
using namespace std;
int x[][];
int main()
{
int n;
scanf("%d",&n);
int i=,j=n/,num=;
while(num<=n*n)
{
int ii=(i%n+n)%n;
int jj=(j%n+n)%n;
x[ii][jj]=num;
if(num%n==) i++;
else --i,j++;
num++;
}
for(i=;i<n;i++)
{
for(j=;j<n;j++)
cout<<x[i][j]<<" ";
cout<<endl;
}
return ;
}

n为奇数


												

Codeforces 710C. Magic Odd Square n阶幻方的更多相关文章

  1. CodeForces 710C Magic Odd Square (n阶奇幻方)

    题意:给它定一个n,让你输出一个n*n的矩阵,使得整个矩阵,每行,每列,对角线和都是奇数. 析:这个题可以用n阶奇幻方来解决,当然也可以不用,如果不懂,请看:http://www.cnblogs.co ...

  2. CodeForces - 710C Magic Odd Square(奇数和幻方构造)

    Magic Odd Square Find an n × n matrix with different numbers from 1 to n2, so the sum in each row, c ...

  3. codeforces 710C Magic Odd Square(构造或者n阶幻方)

    Find an n × n matrix with different numbers from 1 to n2, so the sum in each row, column and both ma ...

  4. 【模拟】Codeforces 710C Magic Odd Square

    题目链接: http://codeforces.com/problemset/problem/710/C 题目大意: 构造一个N*N的幻方.任意可行解. 幻方就是每一行,每一列,两条对角线的和都相等. ...

  5. CodeForces 710C Magic Odd Square

    构造. 先只考虑用$0$和$1$构造矩阵. $n=1$,$\left[ 1 \right]$. $n=3$,(在$n=1$的基础上,最外一圈依次标上$0$,$1$,$0$,$1$......) $\l ...

  6. codeforces 710C C. Magic Odd Square(构造)

    题目链接: C. Magic Odd Square Find an n × n matrix with different numbers from 1 to n2, so the sum in ea ...

  7. [Educational Codeforces Round 16]C. Magic Odd Square

    [Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...

  8. 689D Magic Odd Square 奇数幻方

    1 奇数阶幻方构造法 (1) 将1放在第一行中间一列; (2) 从2开始直到n×n止各数依次按下列规则存放:按 45°方向行走,向右上,即每一个数存放的行比前一个数的行数减1,列数加1 (3) 如果行 ...

  9. Magic Odd Square (思维+构造)

    Find an n × n matrix with different numbers from 1 to n2, so the sum in each row, column and both ma ...

随机推荐

  1. Noip知识点备考

    作为一个oier,适当的整理是有必要的.蒟蒻根据自己的理解,筛选出考noip应当掌握的知识点.可能后期还有解题思路和模板,先挖个坑慢慢补呗. 60级张炳琪Noip知识点总结 可能是本人比较弱,写的内容 ...

  2. zabbix自动发现与监控内存和CPU使用率最高的进程,监测路由器

    https://cloud.tencent.com/info/488cfc410f29d110c03bcf0faaac55b2.html         (未测试) https://www.cnblo ...

  3. 34. Studio字符串分割split用法

    var v = "1,2,3"; var arr = v.toString().split(","); 备注:最好先toString()转为字符串,不然有些情况 ...

  4. 数学公式 AS3应用

    普通做法: var pA:Point=new Point(100,100); var pB:Point=new Point(300,200); var dx:Number=pA.x-pB.x; var ...

  5. 前端-javascript-正则表达式

    1.概念 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <titl ...

  6. find命令之时间戳使用示例

    查看当前目录以及子目录下哪些文件占用的空间最大: find  ./  -type  f  -exec du -m {} \; | sort -nr | head find  ./  -type  f ...

  7. Linux_free(buffer与cache区别)

    一.free命令[root@xen_202_12 /]# free -m             total       used       free     shared    buffers   ...

  8. linux多路径配置

    一.什么是多路径 普通的电脑主机都是一个硬盘挂接到一个总线上,这里是一对一的关系.而到了有光纤组成的SAN环境,或者由iSCSI组成的IPSAN环境,由于主机和存储通过了光纤交换机或者多块网卡及IP来 ...

  9. unity 返回子对象组件

    Component[] GetComponentsInChildren(Type t, bool includeInactive = false); //includeInactive: 是否查找非激 ...

  10. 判断是否有TrueType字体

    function IsTrueTypeAvailable : bool;var {$IFDEF WIN32}  rs : TRasterizerStatus; {$ELSE}  rs : TRaste ...