博客
关于我
紫书——蛇形填数
阅读量:357 次
发布时间:2019-03-04

本文共 467 字,大约阅读时间需要 1 分钟。

#include
#include
//#include
#define maxn 20using namespace std;int a[maxn][maxn];int main(){ int n,x,y,tot=0; cin>>n; memset(a,0,sizeof(a)); tot=a[x=0][y=n-1]=1; while(tot
=0&&!a[x][y-1]) a[x][--y]=++tot; while(x-1>=0&&!a[x-1][y]) a[--x][y]=++tot; while(y+1

蛇形矩阵,1的位置在右上角,先判断,再移动,如果越界就回来。

!a[x][y]是因为初始化数组为0,如果碰到已经填好的数字了就缩回去,
x,y满足小于等于n的条件,表示n行n列。
++tot,先加1,再赋值。

转载地址:http://cqdr.baihongyu.com/

你可能感兴趣的文章
net包之IPConn
查看>>
net发布的dll方法和类显示注释信息(字段说明信息)[图解]
查看>>
Net操作配置文件(Web.config|App.config)通用类
查看>>
NeurIPS(神经信息处理系统大会)-ChatGPT4o作答
查看>>
neuroph轻量级神经网络框架
查看>>
Neutron系列 : Neutron OVS OpenFlow 流表 和 L2 Population(7)
查看>>
NEW DATE()之参数传递
查看>>
New Relic——手机应用app开发达人的福利立即就到啦!
查看>>
new 一个button 然后dispose,最后这个button是null吗???
查看>>
next项目部署到服务器pm2进程守护
查看>>
nexus上传jar
查看>>
Nexus指南中的更新强调集成和透明度的重要性
查看>>
Nexus指南已经发布
查看>>
Nexus(1):Nexus的安装与配置
查看>>
NFinal学习笔记 02—NFinalBuild
查看>>
NFS
查看>>
NFS Server及Client配置与挂载详解
查看>>
NFS 服务配置篇
查看>>
NFS共享文件系统搭建
查看>>
nfs复习
查看>>