振兴中华
来源:互联网 发布:阿里伯克 052d数据对比 编辑:程序博客网 时间:2024/06/05 00:11
public class 振兴中华 {
/*
* 标题: 振兴中华
小明参加了学校的趣味运动会,其中的一个项目是:跳格子。
地上画着一些格子,每个格子里写一个字,如下所示:(也可参见p1.jpg)
从我做起振
我做起振兴
做起振兴中
起振兴中华
比赛时,先站在左上角的写着“从”字的格子里,可以横向或纵向跳到相邻的格子里,但不能跳到对角的格子或其它位置。一直要跳到“华”字结束。
要求跳过的路线刚好构成“从我做起振兴中华”这句话。
请你帮助小明算一算他一共有多少种可能的跳跃路线呢?
答案是一个整数,请通过浏览器直接提交该数字。
注意:不要提交解答过程,或其它辅助说明类的内容。
*/
static int sum=0;
static int arr[][] ={
{1,2,3,4,5},
{2,3,4,5,6},
{3,4,5,6,7},
{4,5,6,7,8},
};
static int [][] copy=new int [4][5];
public static void main(String args[]){
int X=0;
int Y=0;
for(int i=0;i<4;i++){
for(int j=0;j<5;j++){
copy[i][j]=10;
}
}
go(X,Y);
System.out.println(sum);
}
private static void go(int X, int Y) {
copy[X][Y]=arr[X][Y];
//移动
if(X!=3&&arr[X][Y]+1==arr[X+1][Y]){
go(X+1, Y);
}
if(Y!=4&&arr[X][Y]+1==arr[X][Y+1]){
go(X, Y+1);
}
if(X==3&&Y==4){
System.out.println("进入循环!");
sum++;
for(int i=0;i<4;i++){
for(int j=0;j<5;j++){
if(copy[i][j]==1){
System.out.print("从");
}else if(copy[i][j]==2){
System.out.print("我");
}else if(copy[i][j]==3){
System.out.print("做");
}else if(copy[i][j]==4){
System.out.print("起");
}else if(copy[i][j]==5){
System.out.print("振");
}else if(copy[i][j]==6){
System.out.print("兴");
}else if(copy[i][j]==7){
System.out.print("中");
}else if(copy[i][j]==8){
System.out.print("华");
}else{
System.out.print("口");
}
}
System.out.println("");
}
}
copy[X][Y]=10;
}
}
/*
* 标题: 振兴中华
小明参加了学校的趣味运动会,其中的一个项目是:跳格子。
地上画着一些格子,每个格子里写一个字,如下所示:(也可参见p1.jpg)
从我做起振
我做起振兴
做起振兴中
起振兴中华
比赛时,先站在左上角的写着“从”字的格子里,可以横向或纵向跳到相邻的格子里,但不能跳到对角的格子或其它位置。一直要跳到“华”字结束。
要求跳过的路线刚好构成“从我做起振兴中华”这句话。
请你帮助小明算一算他一共有多少种可能的跳跃路线呢?
答案是一个整数,请通过浏览器直接提交该数字。
注意:不要提交解答过程,或其它辅助说明类的内容。
*/
static int sum=0;
static int arr[][] ={
{1,2,3,4,5},
{2,3,4,5,6},
{3,4,5,6,7},
{4,5,6,7,8},
};
static int [][] copy=new int [4][5];
public static void main(String args[]){
int X=0;
int Y=0;
for(int i=0;i<4;i++){
for(int j=0;j<5;j++){
copy[i][j]=10;
}
}
go(X,Y);
System.out.println(sum);
}
private static void go(int X, int Y) {
copy[X][Y]=arr[X][Y];
//移动
if(X!=3&&arr[X][Y]+1==arr[X+1][Y]){
go(X+1, Y);
}
if(Y!=4&&arr[X][Y]+1==arr[X][Y+1]){
go(X, Y+1);
}
if(X==3&&Y==4){
System.out.println("进入循环!");
sum++;
for(int i=0;i<4;i++){
for(int j=0;j<5;j++){
if(copy[i][j]==1){
System.out.print("从");
}else if(copy[i][j]==2){
System.out.print("我");
}else if(copy[i][j]==3){
System.out.print("做");
}else if(copy[i][j]==4){
System.out.print("起");
}else if(copy[i][j]==5){
System.out.print("振");
}else if(copy[i][j]==6){
System.out.print("兴");
}else if(copy[i][j]==7){
System.out.print("中");
}else if(copy[i][j]==8){
System.out.print("华");
}else{
System.out.print("口");
}
}
System.out.println("");
}
}
copy[X][Y]=10;
}
}
0 0
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- Java语言基础(二)---程序流程控制语句、函数
- JavaScript中的闭包
- 世纪末的星期
- OpenVPN不能在Android5.0(Lollipop)使用的问题分析
- 最大公约数
- 振兴中华
- 51Nod-点头网-1035 最长的循环节
- Apache Spark MLlib学习笔记(七)MLlib决策树类算法源码解析 3
- 欢迎使用CSDN-markdown编辑器
- hdu 2102 A计划 队列
- 打印二叉树两个叶子节点间的路径
- hibernate缓存机制详细分析
- 段错误 (核心已转储)
- C发展史:K&R C/C89/C99/C11 以及 C++发展史: C++98/C++03/C++11