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. jQuery noConflict() 方法

    如何在页面上同时使用 jQuery 和其他框架? jQuery 和其他 JavaScript 框架 正如您已经了解到的,jQuery 使用 $ 符号作为 jQuery 的简写. 如果其他 JavaSc ...

  2. ios专题 - 单例模式的实现

    [原创]http://www.cnblogs.com/luoguoqiang1985 单例模式是什么? 一个类只有一个实例. ----------------------- 这样做有什么好处? 在我的 ...

  3. centos7 玩aapt 安卓应用apk解包工具的安装

    最近在做一个应用市场的项目,需要在centos7下面对apk解包读取其信息,这就想到了使用Google的解包工具aapt,但是由于中国的原因,国内访问原生工具的地址就有些麻烦,这里就贴出地址:http ...

  4. VBA开发经验总结之二:灵活运用工作表属性

    近期,在帮公司写一个销售管理的工具,高强度的开发激发了我对一些以前既有方式的看法,特将几点开发经验总结在此. 1.将工作表及窗体的公共变量及特征变量写为工作表或窗体的属性.此种方法的优点: ① 采用面 ...

  5. js判断用户进入设备代码

    var system ={ win : false, mac : false, xll : false }; //检测平台 var p = navigator.platform; system.win ...

  6. 使用css3画饼图

    CSS3 Gradient介绍参考地址: http://www.cnblogs.com/lhb25/archive/2013/01/30/css3-linear-gradient.html http: ...

  7. 用Xamarin和Visual Studio编写iOS App

    一说开发 iOS app,你立马就会想到苹果的开发语言 Objective C/Swift 和 Xcode.但是,这并不是唯一的选择,我们完全可以使用别的语言和框架. 一种主流的替换方案是 Xamar ...

  8. 精心挑选的12款优秀 jQuery Ajax 分页插件和教程

    在这篇文章中,我为大家收集了12个基于 jQuery 框架的 Ajax 分页插件,这些插件都提供了详细的使用教程和演示.Ajax 技术的出现使得 Web 项目的用户体验有了极大的提高,如今借助优秀的  ...

  9. SKProductsRequest ios 7不调用delegate

    在iOS7中,内购只能在真机上才会调用 - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProdu ...

  10. appFramework在三星某些机型上的兼容问题

    有个问题困扰了安卓哥好几天 一个带有fixed抬头的列表页,在向上swipe的时候,有一定概率会把整个画面滚动上去,就连fixed的部分也移动了. 于是哥觉得是webview的问题,找了各种选项,禁用 ...