345TLE,求大佬指点
查看原帖
345TLE,求大佬指点
916797
ffff0505k楼主2023/1/24 10:36

rt

#include <iostream>
#include <math.h>
using namespace std;

int FinalX=0,FinalY=0,HorseX=0,HorseY=0;

/**judges whether the point is under horse's control*/
bool HorseControls(int x,int y)
{
    if((x==HorseX&&y==HorseY))
    return true;
    if(abs(x-HorseX)==3||abs(y-HorseY)==3)
    return false;
    if((abs(x-HorseX)+abs(y-HorseY))==3)
    return true;
    return false;
}

/** judges whether the point is out of bounds*/
bool out(int x,int y)
{
    if(x>FinalX||y>FinalY)
    return true;
    else return false;
}

/** judges whether the point arrives */
bool arrival(int x,int y)
{
    if(x==FinalX&&y==FinalY)
    return true;
    return false;
}

/** total methods */
long long methods=0;
/** jump function */
void jump(int x,int y)
{
    if(out(x,y)||HorseControls(x,y))
    return;
    if(arrival(x,y))
    {
        methods++;
        return;
    }
    jump(x+1,y);
    jump(x,y+1);
}

int main()
{
    cin>>FinalX>>FinalY>>HorseX>>HorseY;
    jump(0,0);
    cout<<methods;
    return 0;
}
2023/1/24 10:36
加载中...