#include<bits/stdc++.h>
using namespace std;
struct node{
int x,y;
}horse,goal;
int main(){
long long a[25][25];
cin>>goal.x>>goal.y>>horse.x>>horse.y;
for(int i=0;i<=goal.x;i++)
for(int j=0;j<=goal.y;j++) a[i][j]=1;
if(horse.x>=0 && horse.x<=goal.x && horse.x-2>=0 && horse.x-2<=goal.x && horse.x-1>=0&&horse.x-1<=goal.x && horse.x+2>=0&&horse.x+2<=goal.x && horse.x+1>=0&&horse.x+1<=goal.x)
if(horse.y>=0 && horse.y<=goal.y && horse.y-1>=0&&horse.y-1<=goal.y && horse.y-2>=0&&horse.y-2<=goal.y && horse.y+1>=0&&horse.y+1<=goal.y && horse.y+2>=0&&horse.y+2<=goal.y){
a[horse.x][horse.y]=0;
a[horse.x-2][horse.y-1]=0;
a[horse.x-2][horse.y+1]=0;
a[horse.x+1][horse.y+2]=0;
a[horse.x-1][horse.y+2]=0;
a[horse.x+2][horse.y+1]=0;
a[horse.x+2][horse.y-1]=0;
a[horse.x-1][horse.y-2]=0;
a[horse.x+1][horse.y-2]=0;
}
for(int i=1;i<=goal.x;i++) {
if(a[i][0]==0) continue;
a[i][0]=a[i-1][0];
}
for(int i=1;i<=goal.y;i++){
if(a[0][i]==0) continue;
a[0][i]==a[0][i-1];
}
for(int i=1;i<=goal.x;i++)
for(int j=1;j<=goal.y;j++){
if(a[i][j]==0) continue;
a[i][j]=a[i-1][j]+a[i][j-1];
}
for(int i=0;i<=goal.x;i++){
for(int j=0;j<=goal.y;j++)
cout<<a[i][j]<<" ";
printf("\n");
}
if(a[0][0]==0 || (a[0][1]==0&&a[1][0]==0)) cout<<"0";
else cout<<a[goal.x][goal.y];
return 0;
}
有两个测试点出错了,
头秃!!
参考GPT和自己的思路:
你好,关于洛谷 1002 过河卒的问题,我注意到你说有两个测试点出错。首先,我建议你先确定错误信息是什么。在确定错误信息后,可以尝试以下几种方法:
1.检查代码逻辑
看一看代码逻辑是否有错误,排查一下可能的错误情况,比如数据类型、运算符等等。同时也需要注意边界情况,是否考虑得当。
2.检查输入数据
检查是否把输入数据输入正确,是否输入类型、输入范围等信息都符合题目要求。
3.尝试其他样例
对于测试点出错的情况,可以尝试其他样例,以确定代码算法是否正确,也可以排除代码的一些潜在错误。
希望这些方法能够帮到你,如果你还有问题,可以继续向我提问。
参考GPT和自己的思路:
首先,可以看出你的代码没有考虑到马跳出棋盘的情况,另外在计算行走方案数时,有一些地方赋值操作错误。
为了能够更准确地判断代码的问题所在,需要你提供具体的错误信息或者测试点编号。否则,无法给出更具体的答复。建议你仔细检查自己的代码,特别是边界处理和值的计算部分,同时参考题目描述和样例,确保程序的正确性。