CodeForces 710C Magic Odd Square
构造。
先只考虑用$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的更多相关文章
- Codeforces 710C. Magic Odd Square n阶幻方
C. Magic Odd Square time limit per test:1 second memory limit per test:256 megabytes input:standard ...
- 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 ...
- 【模拟】Codeforces 710C Magic Odd Square
题目链接: http://codeforces.com/problemset/problem/710/C 题目大意: 构造一个N*N的幻方.任意可行解. 幻方就是每一行,每一列,两条对角线的和都相等. ...
- 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 ...
- CodeForces 710C Magic Odd Square (n阶奇幻方)
题意:给它定一个n,让你输出一个n*n的矩阵,使得整个矩阵,每行,每列,对角线和都是奇数. 析:这个题可以用n阶奇幻方来解决,当然也可以不用,如果不懂,请看:http://www.cnblogs.co ...
- 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 ...
- [Educational Codeforces Round 16]C. Magic Odd Square
[Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...
- 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 ...
- 689D Magic Odd Square 奇数幻方
1 奇数阶幻方构造法 (1) 将1放在第一行中间一列; (2) 从2开始直到n×n止各数依次按下列规则存放:按 45°方向行走,向右上,即每一个数存放的行比前一个数的行数减1,列数加1 (3) 如果行 ...
随机推荐
- Apache HttpServer Installing the apache2.2 service <OS 5>拒绝访问. :Failed to open the WinNT service manager
Installing the apache2.2 service<OS 5>拒绝访问. :Failed to open the WinNT service manager 只需要于管理员 ...
- .NET 微信开放平台接口(接收短信、发送短信)
.NET 微信开放平台接口(接收短信.发送短信) 前两天做个项目用到了微信api功能.项目完成后经过整理封装如下微信操作类. 以下功能的实现需要开发者已有微信的公众平台账号,并且开发模式已开启.接口配 ...
- web开发相关
Session相关 关了浏览器session当然仍然存在,因为session是储存在服务器端的,而服务器是不可能知道你有没有关掉浏览器. 服务器只是简单的保持session接受用户请求,只有当sess ...
- JavaScript怎么上传图片
JavaScript怎么上传图片 在XMLHttpRequest Level2出台之前,大多数的异步上传图片都是利用iframe去实现的. 至于具体的实现细节,我就不在这边啰嗦的,Google一下就有 ...
- 【c++】指针参数是如何传递内存的
[c++]指针参数是如何传递内存的 如果函数的参数是一个指针,不要指望用该指针去动态申请内存.如下: void GetMemory(char *p, int num) { p = (char *) ...
- easyui tree 的数据格式转换
一般用来储存树数据的数据库表都含有两个整型字段:id pid,所以我们查询出来的List一般是这样的(约定pId为-1的节点为根节点): var serverList = [ {id : 2,pid ...
- 一步一步深入spring(7)-- 整合spring和JDBC的环境
1.配置数据源 (1).添加支持数据源的jar包commons-dbcp.jar .commons-pool.jar 当然也要添加其他的spring用到的jar以及这里用到的数据库mysql的jar ...
- flowplayer视频播放插件
flowplayer视频播放插件 最近项目中需要添加播放视频的功能,视频文件是flv格式的.在网上找了一些jQuery视频播放插件,还是觉得“flowplayer”要好一些.特将使用方法记录一下. f ...
- eclipse debug 多线程
以前用到过许多线程开发,对多线程开发也算是小有点心得,但一开始多线程开发的时候,碰到很多壁.但总得来说,有个好的工具总是能事半功倍.我用的工具是eclipse,在开发多线程时,其debug模式是能直接 ...
- Oracle体系结构及备份(十七)——bg-others
一 其他进程 Archiver (ARCn) Oneor more archiver processes copy the redo log files to archival storage whe ...