蛇形填数(JAVA语言)
package 第三章;
import java.util.Scanner;
public class 蛇形填数 {
public static void main(String[] args)
{
// TODO Auto-generated method stub
Scanner in=new Scanner(System.in);
int n=in.nextInt();
int a[][]=new int[n][n];
int x=0,y=n-1;
int t=1;
a[0][n-1]=t;
while(t<n*n) {
while(x+1<=n-1&&a[x+1][y]==0)
{
a[++x][y]=++t;
}
while(y-1>=0&&a[x][y-1]==0)
{
a[x][--y]=++t;
}
while(x-1>=0&&a[x-1][y]==0)
{
a[--x][y]=++t;
}
while(y+1<=n-1&&a[x][y+1]==0)
{
a[x][++y]=++t;
}
}
for(x=0;x<n;x++)
{
for(y=0;y<n;y++)
{
System.out.printf("%3d",a[x][y]);
}
System.out.println();
}
}
}
蛇形填数(JAVA语言)的更多相关文章
- 【OI】蛇形填数题的深入探究
题目:在 n×n 方阵里填入 1,2,...n×n, 要求蛇形填数.例如,n=4 时方阵为: 10 11 12 1 9 16 13 2 8 15 14 3 7 6 ...
- ACM 蛇形填数
蛇形填数 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 在n*n方陈里填入1,2,...,n*n,要求填成蛇形.例如n=4时方陈为:10 11 12 19 16 1 ...
- nyoj 33 蛇形填数
蛇形填数 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 在n*n方陈里填入1,2,...,n*n,要求填成蛇形.例如n=4时方陈为: 10 11 ...
- <蛇形填数>--算法竞赛 入门经典(第2版)- 3.1 数组 程序3-3 蛇形填数
蛇形填数: 在n×n方阵里填入1,2,....,n×n,要求填成蛇形.例如,n = 4 时方阵为: 10 11 12 1 9 16 13 2 8 15 14 3 7 ...
- ny33 蛇形填数
蛇形填数 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 在n*n方陈里填入1,2,...,n*n,要求填成蛇形.例如n=4时方陈为: 10 11 12 1 9 16 1 ...
- 【ACM】蛇形填数 - 逻辑怪
蛇形填数 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 在n*n方陈里填入1,2,...,n*n,要求填成蛇形.例如n=4时方陈为:10 11 12 19 16 1 ...
- 梦工厂实验室 蛇形填数 dfs
问题 D: 蛇形填数 时间限制: 3 Sec 内存限制: 64 MB提交: 28 解决: 5[提交][状态][讨论版] 题目描述 在n*n方阵里填入1,2,...,n*n,要求填成蛇形.例如n=4 ...
- nyoj_33_蛇形填数_201308221636
蛇形填数时间限制:3000 ms | 内存限制:65535 KB 难度:3描述 在n*n方陈里填入1,2,...,n*n,要求填成蛇形.例如n=4时方陈为:10 11 12 19 16 13 28 ...
- nyoj33 蛇形填数
蛇形填数 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描写叙述 在n*n方陈里填入1,2,...,n*n,要求填成蛇形.比如n=4时方陈为: 10 11 12 1 9 16 ...
随机推荐
- Linux错误记录贴
add-apt-repository 不要写成 add-apt-repository service 不要写成 sevice 总之在打命令的时候要注意不要拼错单词 对于ls命令权限不够我们可以先su ...
- Chrome DevTools & performance & keywords
Chrome DevTools & performance & keywords performance / 优化性能 https://developers.google.com/we ...
- 最新 Vue 源码学习笔记
最新 Vue 源码学习笔记 v2.x.x & v3.x.x 框架架构 核心算法 设计模式 编码风格 项目结构 为什么出现 解决了什么问题 有哪些应用场景 v2.x.x & v3.x.x ...
- TensorFlow & Machine Learning
TensorFlow & Machine Learning TensorFlow 实战 传统方式 规则 + 数据集 => 答案 无监督学习 机器学习 神经元网络 答案 + 数据集 =&g ...
- how to fetch a group promise api in order with the returned resolved result
how to fetch a group promise api in order with the returned resolved result promise 一组依次请求,generator ...
- nest.js tutorials
nest.js tutorials A progressive Node.js framework https://docs.nestjs.com//firststeps nest.js CLI ht ...
- browsers simulator
browsers simulator https://developers.google.com/web/tools/chrome-devtools/device-mode/testing-other ...
- learning-js-by-reading-source-codes
learning-js-by-reading-source-codes BigInt https://github.com/learning-js-by-reading-source-codes/lo ...
- nodejs 创建tcp/udp服务器和客户端
TCP server // https://nodejs.org/api/net.html const net = require("net"); // https://nodej ...
- NGK推出SPC算力币,开启算力新玩法!
这两天,NGK公链再度上了热搜.因为既成功的打造DeFi生态以后,NGK又将目光对准了算力市场.试图通过算力代币化,让NGK算力持有者可以获得算力代币,同时,如果不想要了,算力持有者也可以抛售代币. ...