Compile Error求改进
查看原帖
Compile Error求改进
1126325
Indestructible楼主2024/1/23 12:17

想了1小时,编辑10分钟,结果……直接CE

思路

也就是递推。

用 counted[30][30] 存步数,设置 counted[0][0]=1 ,一斜行一斜行的算,即先算 counted[1][0],counted[0][1] ,再算 counted[2][0],counted[1][1],counted[0][2] ……

最后输出 counted[n][m] 即可。

代码

CE了,但本地编译通过,而且通过了样例!

#include<bits/stdc++.h>
using namespace std;
#define _int unsigned long long
#define SIZE 30
_int counted[SIZE][SIZE]={1};
_int control_point[9][2];
_int op[9][2]={0,0,1,2,2,1,-1,-2,-2,-1,-1,2,-2,1,1,-2,2,-1};
_int bx,by,horse[2];
bool check(_int x,_int y){
    for (_int i=0;i<9;i++)
        if (x==control_point[i][0] && y==control_point[i][1])
            return false;
    return x>=0 && y>=0 && x<=bx && y<=by;
}
int main(){
    scanf("%llu%llu%llu%llu",&bx,&by,&horse[0],&horse[1]);
    for (_int i=0;i<9;i++) for (_int j=0;j<2;j++)
        control_point[i][j]=op[i][j]+horse[j];
    for (_int i=1;i<=bx+by;i++){
        for (_int j=0,k=i,x1,y1,x2,y2;j<=i;j++,k--){
            x1=j-1,y1=k,x2=j,y2=k-1;
            if (check(x1,y1)) counted[j][k]+=counted[x1][y1];
            if (check(x2,y2)) counted[j][k]+=counted[x2][y2];
        }
    }
    printf("%llu",counted[bx][by]);
    return 0;
}
2024/1/23 12:17
加载中...