题目要求
P2615题目链接
注意题目说的是,幻方的N必定是奇数(实测确实不能是偶数),那就不需要检测了。
实际模拟,就是一个地图,按指定的要求移动就行。 这种题,看着吓人,但是其实严格按照说编写代码就行了,并不需要自己设计什么算法。
AC代码(Java语言描述)import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int num = scanner.nextInt();
scanner.close();
int[][] array = new int[num][num];
int last_x = 0, last_y = num/2;
//肯定是奇数
array[0][last_y] = 1;
for (int i = 2; i
关注
打赏
热门博文
- 【Linux】Ubuntu20.04安装和卸载MySQL8
- 【Linux】Ubuntu 20.04 报错 curl: (23) Failure writing output to destination 的解决方法
- 【Java】JUnit 4.13.2 警告 ‘assertEquals(double, double)‘ is deprecated 的解决方法
- 【JavaScript】处理 @parcel/transformer-js: Browser scripts cannot have imports or exports.
- 【Node.js】Windows环境安装配置NVM和Node.js
- 【Python】处理TypeError: Plain typing.NoReturn is not valid as type argument
- 【Python】Matplotlib可视化50例
- 【C语言】C语言修改MySQL数据库
- 【Java】从默认包导入类和对象报错的解决方法
- 【Java】panel.getGraphics()报错空指针异常的解决方法