C语言 16*16棋盘 马数小于4的马拦过河卒问题
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/07/15 02:00:57
C语言 16*16棋盘 马数小于4的马拦过河卒问题
#include
struct node{
int right;
int down;
int x,y;
}stack[40];
struct horse{
int x,y;
}horse[8];
int test(int x,int y,struct horse *h,int k){
int i;
for(i = 0; i < k; i++)
if(h[i].x == x && h[i].y == y)
return 1;
return 0;
}
int main(){
int xd,yd,xh,yh,i,k,m;
int b[] = {-2,-1,1,2,2,1,-1,-2};
int c[] = {1,2,2,1,-1,-2,-2,-1};
while(scanf("%d%d%d%d",&xd,&yd,&xh,&yh)!=EOF){
for(k = i = 0; i < 8; i++){
if(xh+c[i]xd || yh+b[i]yd)
continue;
horse[k].x = xh + c[i];
horse[k].y = yh + b[i];
k++;
}
stack[0].x=stack[0].y=stack[0].down=stack[0].right=0;
for(m = i = 0; i >= 0;){
if(stack[i].x == xd && stack[i].y == yd){
i--;
m++;
}
if(stack[i].down == 0){
stack[i+1].y = stack[i].y + 1;
stack[i+1].x = stack[i].x;
stack[i].down = 1;
i++;
stack[i].down = stack[i].right = 0;
}
else if(stack[i].right == 0){
stack[i+1].x = stack[i].x + 1;
stack[i+1].y = stack[i].y;
stack[i].right = 1;
i++;
stack[i].down = stack[i].right = 0;
}
else{
i--;
continue;
}
if( stack[i].x > xd || stack[i].y > yd ||
test(stack[i].x,stack[i].y,horse,k) ||
(stack[i].x == xh && stack[i].y == yh) ){
i--;
continue;
}
}
printf("%d\n",m);
}
return 0;
}
struct node{
int right;
int down;
int x,y;
}stack[40];
struct horse{
int x,y;
}horse[8];
int test(int x,int y,struct horse *h,int k){
int i;
for(i = 0; i < k; i++)
if(h[i].x == x && h[i].y == y)
return 1;
return 0;
}
int main(){
int xd,yd,xh,yh,i,k,m;
int b[] = {-2,-1,1,2,2,1,-1,-2};
int c[] = {1,2,2,1,-1,-2,-2,-1};
while(scanf("%d%d%d%d",&xd,&yd,&xh,&yh)!=EOF){
for(k = i = 0; i < 8; i++){
if(xh+c[i]xd || yh+b[i]yd)
continue;
horse[k].x = xh + c[i];
horse[k].y = yh + b[i];
k++;
}
stack[0].x=stack[0].y=stack[0].down=stack[0].right=0;
for(m = i = 0; i >= 0;){
if(stack[i].x == xd && stack[i].y == yd){
i--;
m++;
}
if(stack[i].down == 0){
stack[i+1].y = stack[i].y + 1;
stack[i+1].x = stack[i].x;
stack[i].down = 1;
i++;
stack[i].down = stack[i].right = 0;
}
else if(stack[i].right == 0){
stack[i+1].x = stack[i].x + 1;
stack[i+1].y = stack[i].y;
stack[i].right = 1;
i++;
stack[i].down = stack[i].right = 0;
}
else{
i--;
continue;
}
if( stack[i].x > xd || stack[i].y > yd ||
test(stack[i].x,stack[i].y,horse,k) ||
(stack[i].x == xh && stack[i].y == yh) ){
i--;
continue;
}
}
printf("%d\n",m);
}
return 0;
}
C语言 16*16棋盘 马数小于4的马拦过河卒问题
【问题描述】棋盘上A点有一个过河卒,需要走到目标B点.卒行走的规则:可以向下、或者向右.同时在棋盘上C点有一个对方的马,
过河卒救急棋盘上A点有一个过河卒,需要走到目标B点.卒行走的规则:可以向下、或者向右.同时在棋盘上C点有一个对方的马,该
C语言——马拦过河卒.看看我的算法错哪了,并改正.
pascal马拦过河卒问题
输入一个整数,然后输出小于等于该数的所有素数,C语言问题.
马拦过河卒 C语言特别经典的递如图,A 点有一个过河卒,需要走到目标 B 点.卒行走规则:可以向下、或者向右
回答下面的问题在棋盘上,第一格放1粒米,第二格放2粒,第三格放4粒,第四格放16粒……按这个方法放满整个棋盘.棋盘有64
马的走法C语言算法半张中国象棋棋盘,即5×9棋盘,左上角记为A(1,1),求从A点的马,只能向右行走,走到点B(m,n)
求一个关于C语言的程序! 问题:输入若干整数,统计大于0和小于0的数!
输入一个整数,求输出小于等于该数的所有素数,C语言问题.看看哪出问题了..
c语言交换两个数的问题?