构造。

先只考虑用$0$和$1$构造矩阵。

$n=1$,$\left[ 1 \right]$。

$n=3$,(在$n=1$的基础上,最外一圈依次标上$0$,$1$,$0$,$1$......)

$\left[ {\begin{array}{*{20}{c}}
0&1&0\\
1&1&1\\
0&1&0
\end{array}} \right]$。

$n=5$,(在$n=3$的基础上,最外一圈依次标上$1$,$0$,$1$,$0$......)

$\left[ {\begin{array}{*{20}{c}}
1&0&1&0&1\\
0&0&1&0&0\\
1&1&1&1&1\\
0&0&1&0&0\\
1&0&1&0&1
\end{array}} \right]$。

输出的时候我们再将$1$至${n^2}$这些数替换$0$和$1$。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
} int a[][],n,st; void work(int r1,int c1,int r2,int c2,int f)
{
for(int j=c1;j<=c2;j++) a[r2][j]=a[r1][j]=f, f=f^;
f=f^;for(int i=r1;i<=r2;i++) a[i][c2]=a[i][c1]=f,f=f^;
} int main()
{
scanf("%d",&n);
if(n%==) st=; else st=;
int x1=,y1=,x2=n,y2=n;
while()
{
work(x1,y1,x2,y2,st);
if(x1==x2&&y1==y2) break;
x1++; y1++; x2--; y2--; st=st^;
} int k1=,k2=;
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
if(a[i][j]%==) a[i][j]=k1, k1=k1+;
else a[i][j]=k2, k2=k2+;
}
} for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
printf("%d ",a[i][j]);
}
printf("\n");
}
return ;
}

CodeForces 710C Magic Odd Square的更多相关文章

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

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

  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

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

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

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

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

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

  9. 689D Magic Odd Square 奇数幻方

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

随机推荐

  1. 基于Redis的CustomerSessionProvider(二)

    接一的考虑,那么就做Redis的SessionProvider就非常简单了,只考虑整个Session的缓存,主要实现以下两个函数就可以了 public override SessionStateSto ...

  2. 对无返回值、使用Action或Func作为参数、多重载的方法进行单元测试

    VS2012 Unit Test(Void, Action, Func) —— 对无返回值.使用Action或Func作为参数.多重载的方法进行单元测试 [提示] 1. 阅读文本前希望您具备如下知识: ...

  3. struts2 action 接受数组参数为Null的问题

    public List<FormulaDetail> formulaDetails; public List<FormulaDetail> getFormulaDetails( ...

  4. 实现了一个简单的key-value存储系统

    实现了一个简单的key-value存储系统 源码下载: kvfs.rar 正文: 所谓的Key-Value就是每次存储一个数据时,是根据Key进行索引存储的.为了实现Key的快速查找功能,我使用了B- ...

  5. 使用Func<T1, T2, TResult>

    使用Func<T1, T2, TResult> 委托返回匿名对象   Func<T1, T2, TResult> 委托 封装一个具有两个参数并返回 TResult 参数指定的类 ...

  6. pipe----管道----fork

    #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <string.h&g ...

  7. openlayers 加载瓦片详解 一

    在这先说点题外话,本人在研究webgl 三维球过程中惊人发现,openlayers 的开发人员也在研究webgl并经证实他们也正在研发基于 webgl的三维gis开源平台,这可能是首个开源的三维平台, ...

  8. C#中的文件操作2

    1. 读取文件的方法: 1.  声明一个文件流: 目的是为了内存与文件之间的桥梁,可以进行数据的往来. FileStream fs = new FileStream(filename,FileMode ...

  9. C语言之带有返回值的函数

    带有返回值的函数 语法: 类型 函数名(参数列表){ 函数体; return 数据; } 例: int getSum(int num1,int num2){ int sum = num1 + num2 ...

  10. 从c#基础到java基础的学习的感悟

    从进入培训公司到现在已经有三周多了,我想我和绝大多数人一样,能考虑进入培训学校,肯定是心理做好了准备的,那就是只有一个目的学好这门技术,从之前的开班典礼来看,从每个同学的自我介绍,我们这的大部分人来这 ...