求数据范围

回复帖子 返回题目

@ 战术目镜 2017-12-07 20:52 回复

谢谢 还有个问题,我的程序会re,求大佬们解释

#include<iostream>
#include<cmath>
#include<vector>
#include<map>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<queue>
#include<climits>
#include<set>
#include<cstring>
using namespace std;
struct position
{
    int xx;
    int yy;
};
position final,horse;
bool control[100][100];
void in();
long long find(int x,int y);
int main()
{
    in();
    cout << find(final.xx,final.yy);
    return 0;
}
void in()
{
    cin >> final.xx >> final.yy >> horse.xx >> horse.yy;
    memset(control,0,sizeof(control));
    control[horse.xx][horse.yy] = 1;
    control[horse.xx+2][horse.yy+1] = 1;
    control[horse.xx+2][horse.yy-1] = 1;
    control[horse.xx+1][horse.yy+2] = 1;
    control[horse.xx+1][horse.yy-2] = 1;
    control[horse.xx-1][horse.yy+2] = 1;
    control[horse.xx-1][horse.yy-2] = 1;
    control[horse.xx-2][horse.yy+1] = 1;
    control[horse.xx-2][horse.yy-1] = 1;
}
long long find(int x,int y)
{
    if(control[x][y])
    {
        return 0;
    }
    if(x < 0 || y < 0)
    {
        return 0;
    }
    if(x == 0 && y == 0)
    {
        return 1;
    }
    long long ans = find(x,y-1) + find(x-1,y);
    cout << ans << endl;
    return ans;
}
@ 名侦探柯北2号 2017-12-07 21:17 回复

我试出了2个wa和3个tle!

PS:本蒟蒻AC代码:

#include<cstdio>
long long x,y,n,m,a[30][30],f[30][30];
void z(long long x,long long y)
{
    f[x][y]=1;
    f[x-1][y-2]=1;
    f[x-2][y-1]=1;
    f[x-2][y+1]=1;
    f[x-1][y+2]=1;
    f[x+1][y-2]=1;
    f[x+2][y-1]=1;
    f[x+2][y+1]=1;
    f[x+1][y+2]=1;
}
void work()
{
    a[1][0]=1;
    for(int i=1;i<=n+1;i++)
        for(int j=1;j<=m+1;j++)
                if(f[i-1][j-1]) a[i][j]=0;
            else a[i][j]=a[i-1][j]+a[i][j-1];
    printf("%lld",a[n+1][m+1]);
}
int main()
{
    scanf("%lld%lld%lld%lld",&n,&m,&x,&y);
    z(x,y);
    work();
}