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) 如果行 ...
随机推荐
- java web项目基础
listener,filter,servlet的初始化顺序 web.xml中可以配置如下信息: context-param,listener,filter,servlet. 他们的加载顺序和在we ...
- formValidator
formValidator输入验证.异步验证实例 + licenseImage验证码插件实例应用 实例技术:springmvc 实现功能:完整用户登录流程.输入信息规则校验.验证码异步校验. 功能 ...
- [转]Data Structure Recovery using PIN and PyGraphviz
Source:http://v0ids3curity.blogspot.com/2015/04/data-structure-recovery-using-pin-and.html --------- ...
- [转]Building a Basic Fuzzer with GDB: The Five Minute GDB Scripting Tutorial
link:http://www.praetorian.com/blog/building-a-basic-fuzzer-with-gdb-the-five-minute-gdb-scripting-t ...
- hdu4414(DFS 找十字架数量)
Problem Description The Nazca Lines are a series of ancient geoglyphs located in the Nazca Desert in ...
- 教你用shell写CGI程序
以前用shell写过一些cgi的例子.今天向大家介绍一下. CGI是一种接口的标准,并不区分编程语言,也就是说,CGI可以用任何一种语言编写,只要这种语言具有标准输入.输出和环境变量.CGI会将标准输 ...
- ios7学习之路七(隐藏虚拟键盘,解决键盘挡住UITextField问题)
再正式开始之前,先来介绍一下IOS的键盘类型: 一.键盘风格 UIKit框架支持8种风格键盘 typedef enum { UIKeyboardTypeDefault, // 默认键盘:支持所有字符 ...
- C#奇葩关键字
C#奇葩关键字——忐忑 那就认识认识吧,可是又太多,所以也只能是想到哪里是哪里,我们这就让思绪自由飞翔一会吧! 1.@ 这个东东看似和邮件有关啊,但是在C#的世界里,可跟邮件没有一毛钱关系,它是str ...
- Bundles
Bundles 接着在Global.asax文件的Application_Start方法中调用BundleConfig.RegisterBundles方法: protected void Applic ...
- gcc编译器优化给我们带来的麻烦???
gcc编译器优化给我们带来的麻烦??? 今天看到一个很有趣的程序,如下: ? 1 2 3 4 5 6 7 8 9 int main() { const int a = 1; int * ...