解题思路:
用递归遍历每一种情况,并且根据马的位置去掉不能走过的点
注意事项:
参考代码:
#include <stdio.h>
int computer(int x1, int y1, int x, int y, int a, int b);
int main(void)
{
int a, b, x, y;
int count;
scanf("%d%d%d%d", &x, &y, &a, &b);
count = computer(0, 0, x, y, a, b);
printf("%d", count);
return 0;
}
int computer(int x1, int y1, int x, int y, int a, int b)
{
if (x1 == x && y1 == y)
{
return 1;
}
else if (x1 != x && y1 == y)
{
if (x1 == a + 2)
{
if (y1 == b + 1 || y1 == b - 1)
return 0;
else
return computer(x1 + 1, y1, x, y, a, b);
}
else if (x1 == a - 2)
{
if (y1 == b + 1 || y1 == b - 1)
return 0;
else
return computer(x1 + 1, y1, x, y, a, b);
}
else if (x1 == a + 1)
{
if (y1 == b + 2 || y1 == b - 2)
return 0;
else
return computer(x1 + 1, y1, x, y, a, b);
}
else if (x1 == a - 1)
{
if (y1 == b + 2 || y1 == b - 2)
return 0;
else
return computer(x1 + 1, y1, x, y, a, b);
}
else if (x1 == a && y1 == b)
{
return 0;
}
else
return computer(x1 + 1, y1, x, y, a, b);
}
else if (x1 == x && y1 != y)
{
if (x1 == a + 2)
{
if (y1 == b + 1 || y1 == b - 1)
return 0;
else
return computer(x1, y1 + 1, x, y, a, b);
}
else if (x1 == a - 2)
{
if (y1 == b + 1 || y1 == b - 1)
return 0;
else
return computer(x1, y1 + 1, x, y, a, b);
}
else if (x1 == a + 1)
{
if (y1 == b + 2 || y1 == b - 2)
return 0;
else
return computer(x1, y1 + 1, x, y, a, b);
}
else if (x1 == a - 1)
{
if (y1 == b + 2 || y1 == b - 2)
return 0;
else
return computer(x1, y1 + 1, x, y, a, b);
}
else if (x1 == a && y1 == b)
{
return 0;
}
else
return computer(x1, y1 + 1, x, y, a, b);
}
else
{
if (x1 == a + 2)
{
if (y1 == b + 1 || y1 == b - 1)
return 0;
else
return computer(x1, y1 + 1, x, y, a, b) + computer(x1 + 1, y1, x, y, a, b);
}
else if (x1 == a - 2)
{
if (y1 == b + 1 || y1 == b - 1)
return 0;
else
return computer(x1, y1 + 1, x, y, a, b) + computer(x1 + 1, y1, x, y, a, b);
}
else if (x1 == a + 1)
{
if (y1 == b + 2 || y1 == b - 2)
return 0;
else
return computer(x1, y1 + 1, x, y, a, b) + computer(x1 + 1, y1, x, y, a, b);
}
else if (x1 == a - 1)
{
if (y1 == b + 2 || y1 == b - 2)
return 0;
else
return computer(x1, y1 + 1, x, y, a, b) + computer(x1 + 1, y1, x, y, a, b);
}
else if (x1 == a && y1 == b)
{
return 0;
}
else
return computer(x1, y1 + 1, x, y, a, b) + computer(x1 + 1, y1, x, y, a, b);
}
}
0.0分
0 人评分
陶陶摘苹果 (C语言代码)浏览:1652 |
简单的a+b (C语言代码)浏览:594 |
C语言程序设计教程(第三版)课后习题9.4 (Java代码)浏览:1446 |
C语言程序设计教程(第三版)课后习题6.10 (C语言代码)浏览:827 |
蛇行矩阵 (C语言代码)浏览:792 |
【蟠桃记】 (C语言代码)浏览:697 |
2004年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:1368 |
C语言程序设计教程(第三版)课后习题7.1 (C语言代码)浏览:642 |
简单的a+b (C语言代码)浏览:626 |
字符逆序 (C语言代码)浏览:706 |