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 43 5 76 9 8

题义就是N*N的方格里面填数1~N*N,横列斜和为奇数

哎,艰辛啊。。。

#include <bits/stdc++.h>
using namespace std;
#define Maxn 55
int MAP[Maxn][Maxn];
bool visit[Maxn][Maxn];

int main(){
    int N;
    cin >> N;
    memset(visit,false,sizeof(visit));
    for(int i = 1; i <= N; i++){
        for(int j = 1; j <= N; j++){
            if( i >= (j- N/2) && i <= (j + N/2) && i + j >= ((N+3)/2) && i + j <= (N+(N+1)/2) ){
                visit[i][j] = true;
            }else{
                visit[i][j] = false;
            }
        }
    }
    int jishu = 1;
    int oushu = 2;
    for(int i = 1; i <= N; i++){
        for(int j = 1; j <= N; j++){
            if(visit[i][j]){
                cout << jishu << " ";
                jishu += 2;
            }else{
                cout << oushu << " ";
                oushu += 2;
            }
        }
        cout << endl;
    }
}

  

codeforces 710C的更多相关文章

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

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

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

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

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

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

  4. CodeForces 710C Magic Odd Square

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

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

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

  8. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  9. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

随机推荐

  1. angularjs服务常见用法

    服务可以再应用的整个生命周期内保持数据,不会在切换路由或者重新加载视图时被清楚掉(控制器只有在需要时才被实例化) 服务是一个单例对象,在每个应用中只会被实例化一次 服务在应用的生命周期内保存数据 an ...

  2. C++自定义异常处理

    自定义异常类 class MyException { public: MyException() { } MyException(char* str) { msg = str; } MyExcepti ...

  3. PHP设计模式之:建造者模式

    建造者模式: 将一个复杂对象的构造与它的表示分离,使同样的构建过程可以创建不同的表示的设计模式; 目的: 消除其他对象复杂的创建过程 结构图: 优点: 建造者模式可以很好的将一个对象的实现与相关的“业 ...

  4. VS下面的编译错误-----转换到 COFF 期间失败: 文件无效或损坏

    最近写了一个vs的小项目,然后编译的时候vs提示了"转换到 COFF 期间失败: 文件无效或损坏"的问题. 去网上搜索了一个解决方案.原作者的链接是:http://jingyan. ...

  5. python使用__future__

    Python的新版本会引入新的功能,但是,实际上这些功能在上一个老版本中就已经存在了.要“试用”某一新的特性,就可以通过导入__future__模块的某些功能来实现. 例如,Python 2.7的整数 ...

  6. SAP Crystal Dashboard Design 2011 win7 x64 安装

    suggest: unZip the setup package to C:\dashboard\  (make sure that the path cannot contain non-unico ...

  7. XP系统VPN设置

    为了解除公司上网策略限制,或者为了上Google,Facebook,都可以通过设置VPN实现. 要使用VPN需要到VPN服务商注册,链接VPN服务商. ======================== ...

  8. 如何使用 Docker、ECS、Terraform 重建基础架构?

    早期 Segment 基础架构普遍组合在一起.我们通过 AWS 界面设定实例,使用许多闲散的 AMI,并且采用三种不同的部署方式. 然而随着商业的飞速发展,工程师团队的规模不断扩大,基础架构的复杂度也 ...

  9. keil多文件组织方法

    方法一 首先新建一个main.c的文件,加入到项目中,该文件中主要写main函数,然后,新建文件,如delay.c,编写内容之后,不要加入到项目,而是在main.c文件的开始写上#include“de ...

  10. Android GradientDrawable类的详解,设置activity的背景颜色渐变效果

    看到这个例子的标题RoundRects,我的第一感觉是介绍RoundRectShape, 打开例子看了代码却是使用GradientDrawable来实现的. GradientDrawable 支持使用 ...