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. ORM Nhibernate框架在项目中的配置

    在项目中使用 Nhibernet 时,一定要将 配置文件 .xml  编译方式设置为 嵌入式资源,否则在运行项目时就会出现错误. 以下是hibernate.cfg.xml 的配置,在配置中使用的是 M ...

  2. python写批量weblogic爆破脚本

    前言: 整理笔记的时候,发现了weblogic的攻击方法.心里打着算盘看看怎么写 个批量的弱口令爆破脚本.得出了以下思路 思路: 1.利用钟馗之眼采集weblogic的网站,将IP写入到txt 2.添 ...

  3. nginx, supervisor

    Nginx(单进程): 反向代理, 负载均衡.图解 将配置文件 nginx.conf 的 user xx 配置好 xx用户 检查语法 $ sudo service nginx configtest 重 ...

  4. smokeping配置方法

    smokeping配置加Nginx https://lala.im/2821.html  (不完整)

  5. 39. 在linux下装好Tomcat要给 tomcat/bin/下面所有.sh的文件执行权限

    chmod a+x *.sh(赋予可执行的权限)

  6. 视频地址blog加密

    /* JS部分 没处理兼容什么的 */ var id='<?php echo $_GET['id'];?>'; var video = document.getElementById(&q ...

  7. 转发 DDoS攻防战 (一) : 概述

     岁寒 然后知松柏之后凋也   岁寒 然后知松柏之后凋也 ——论语·子罕 (此图摘自<Web脚本攻击与防御技术核心剖析>一书,作者:郝永清先生)    DDoS,即 Distributed ...

  8. HTML5拖动

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  9. Spring boot&Mybatis 启动报错 Failed to auto-configure a DataSource

    *************************** APPLICATION FAILED TO START *************************** Description: Fai ...

  10. C#--Winform项目核心模块--考勤模块

    C#--Winform项目核心模块--考勤模块(一) C#--Winform项目核心--考勤模块(二) C#--Winform项目核心模块--考勤模块(三)