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. c#面向对象基础3

    静态与非静态的区别 (1)在非静态类中既可以有实例成员,也可以有静态成员(static修饰). (2)在调用静态成员的时候要使用:对象名.实例成员. (3)在调用静态成员的时候要使用:类名.静态成员. ...

  2. MVC 4 Razor Design Sample Demo Project

    This is a demo project in MCV 4 razor design which encompases the general design of MVC pattern. The ...

  3. JS实现拖动效果

    有个问题就是该模块要使用定位,因为有left,top属性使用,绝对定位和相对定位都行,当然你也可使用margin-left,和margin-top这2个属性,替换left,top也是可以得 这样就不用 ...

  4. Caused by: java.lang.IllegalStateException: Expected raw type form of org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$Match

    spring 4.0.2,mybatis 3.2.6,aspectjweaver 1.8.10 使用的时候,报错: Caused by: java.lang.IllegalStateException ...

  5. [ilink32 Error] Error: Unresolved external '__fastcall Data::Win::Adodb::TCustomADODataSet

    [ilink32 Error] Error: Unresolved external '__fastcall Data::Win::Adodb::TCustomADODataSet::GetParam ...

  6. XMLTransformProvider

    XMLTransformProvider1 XMLTransformProvider1.TransformRead.SourceXmlDocument := XMLDoc.GetDOMDocument ...

  7. J2SE 8的反射

    1.获得Class的四种方式 //(1) 利用对象调用getClass()方法获取该对象的Class实例 Class<? extends ReflectTest> class1 = new ...

  8. 使用curl发起https请求

    "SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:S ...

  9. 迷你MVVM框架 avalonjs 1.3.8发布

    avalon1.3.8主要是在ms-repeat. ms-each. ms-with等循环绑定上做重大性能优化,其次是对一些绑定了事件的指令添加了roolback,让其CG回收更顺畅. 重构ms-re ...

  10. css 设置元素背景为透明

    要设置某一元素的背景为透明,在 chrome .firefox.opera 下是这样的: rgba 中的最后一个参数 0.4 就是想要的透明度,范围在0-1之间. 在 ie 中一般是这样的: filt ...