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

这个题在中间的菱形区域是奇数,其余为偶数

代码:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath> const int maxn=3e5+5;
typedef long long ll;
using namespace std; int a[maxn];
int b[maxn];
int Map[200][200];
int main()
{
int n;
cin>>n;
memset(Map,0,sizeof(Map));
int cnt1=0;
int cnt2=0;
for(int t=1;t<=n*n;t++)
{
if(t%2==0)
{
a[cnt1++]=t;
}
else
{
b[cnt2++]=t;
}
}
int cnt3=0;
for(int t=0;t<n;t++)
{
for(int j=0;j<n;j++)
{
if(j>=n/2-t&&j<=t+n/2&&j<=n-1+n/2-t&&j>=t-n/2)
{
Map[t][j]=b[cnt3];
cnt3++;
}
}
}
int cnt4=0;
for(int t=0;t<n;t++)
{
for(int j=0;j<n;j++)
{
if(Map[t][j]==0)
{
Map[t][j]=a[cnt4];
cnt4++;
}
}
}
for(int t=0;t<n;t++)
{
for(int j=0;j<n;j++)
{
cout<<Map[t][j]<<" ";
}
cout<<endl;
}
}

Magic Odd Square (思维+构造)的更多相关文章

  1. 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 ...

  2. 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 ...

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

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

  4. Codeforces 710C. Magic Odd Square n阶幻方

    C. Magic Odd Square time limit per test:1 second memory limit per test:256 megabytes input:standard ...

  5. 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 ...

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

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

  7. CodeForces 710C Magic Odd Square

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

  8. 689D Magic Odd Square 奇数幻方

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

  9. CF710C Magic Odd Square 题解

    Content 构造出一个 \(n\times n\) 的矩阵,使得这个矩阵由 \(1\sim n^2\) 这些数字组成,并且这个矩阵的每行,每列,以及对角线的和都为奇数. 数据范围:\(1\leqs ...

随机推荐

  1. conda create -n AlphaPose2018 python=2.7

    conda create -n AlphaPose2018 python=2.7Solving environment: done ==> WARNING: A newer version of ...

  2. Apache rotatelogs命令

    一.简介 rotatelogs 是 Apache 自带的管道日志程序,可以完美的实现日志的轮转功能. 二.语法 Usage: rotatelogs [-v] [-l] [-L linkname] [- ...

  3. export default {} 和new Vue()区别

     1.export default 的用法:相当于提供一个接口给外界,让其他文件通过 import 来引入使用. 而对于export default 和export的区别:  在JavaScript ...

  4. Python基础 之列表、字典、元组、集合

    基础数据类型汇总 一.列表(list) 例如:删除索引为奇数的元素 lis=[11,22,33,44,55] #第一种: for i in range(len(lis)): if i%2==1: de ...

  5. Shiro——概述

    Apache Shiro 是 Java 的一个安全(权限)框架. Shiro 可以非常容易的开发出足够好的应用,其不仅可以用在JavaSE 环境,也可以用在 JavaEE 环境. Shiro 可以完成 ...

  6. 金融卡IC卡知识50问

    1.什么是金融IC卡? 金融IC卡又称为芯片银行卡,是以芯片作为介质的银行卡.芯片卡容量大,可以存储密钥.数字证书.指纹等信息,其工作原理类似于微型计算机,能够同时处理多种功能,为持卡人提供一卡多用的 ...

  7. using JSTL

    http://docs.oracle.com/javaee/5/tutorial/doc/bnake.html JSTL(JSP Standard Tag Library)

  8. Displaying Speed and Direction Symbology from U and V vectors (转)

    This blog shows you how to calculate and symbolize wind or current speed and direction when the unde ...

  9. java并发机制的底层实现原理

    volatile是轻量级的synchronized,它在多处理器开发中保证了共享变量的"可见性".可见性是说当一个线程修改一个共享变量时,另外一个线程能读到这个修改的值. vola ...

  10. Map存储容量及内存占用测试

    Integer a = 1; long start = 0; long end = 0; // 先垃圾回收 System.gc(); start = Runtime.getRuntime().free ...