模拟,注意为偶数的情况

 #include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<queue>
#include<stack>
#include<cmath>
#include<algorithm>
#include<malloc.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
const int N=;
#define LL long long
const double eps = 1e-;
const double pi = acos(-);
int g[][];
// inline int r(){
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0'){if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
// return x*f;
// }
int n,x,y;
int mp[][];
int main()
{
scanf("%d",&n);
x = ,y = (n+)/;
mp[x][y]=;
for(int i=;i<=n*n;i++)
{
if(x==&&y!=n)
x=n,y++;
else if(x!=&&y==n)
x--,y=;
else if(x==&&y==n)
x++;
else if(!mp[x-][y+])
x--,y++;
else
x++;
mp[x][y]=i;
}
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++){
if(j==)
printf("%d",mp[i][j]);
else
printf(" %d",mp[i][j]);
}
printf("\n");
}
return ;
}

最新文章

  1. HDU 1693 Eat the Trees(插头DP、棋盘哈密顿回路数)+ URAL 1519 Formula 1(插头DP、棋盘哈密顿单回路数)
  2. ThinkPHP3.2.2 Widget扩展以及widget demo实例
  3. mybatis mapper.xml 配置文件问题(有的错误xml是不报的) 导致服务无法启动 。
  4. Linux文件系统性能优化 (转)
  5. QTREE2 spoj 913. Query on a tree II 经典的倍增思想
  6. 【Sql Server】使用触发器把一个表中满足条件的数据部分字段插入到另一个表中
  7. Asp.Net读写XML简单方法
  8. A Tour of Go Errors
  9. Optimal Logging
  10. jQuery工作原理解析以及源代码示例
  11. Java开发中的23+2种设计模式学习个人笔记(未完待续)
  12. Asp.Net路由重写为用户名或者ID
  13. Headless Android开发板的调试及远程显示和控制
  14. go不使用工具包将大写字符转成小写字符的方法
  15. 查询SQLSERVER中系统表结构
  16. OpenNI1.5获取华硕XtionProLive深度图和彩色图并用OpenCV显示
  17. Mac系统配置JDK环境变量
  18. Kafka深度解析(如何在producer中指定partition)(转)
  19. 有关一道printf 的面试题
  20. java中的上转型解释(多态的另一种)

热门文章

  1. dragsort拖动排序
  2. 响应式菜单(bootstrap)
  3. [转载]c# winform 获取当前程序运行根目录
  4. [转载]easyui datagrid 时间格化(JS 日期时间本地化显示)
  5. smarty foreach 最全用法
  6. 为你的PHP程序选择合适的密码库(初稿)
  7. 电商安全无小事,如何有效地抵御 CSRF 攻击?
  8. CSU1321+SPFA
  9. poj 2065 SETI 高斯消元
  10. [Unity菜鸟] Unity鼠标双击,鼠标函数整理(未完)