View Code of Problem 1005

<span style="font-size:18px;">#include <iostream>
#include<cstdio>
#include<cstring>

using namespace std;

int mp[100][100];
int dx[]={-1,1,-2,2,-2,2,-1,1};
int dy[]={-2,-2,-1,-1,1,1,2,2};
int s;
int n,m;
int a[1000];
int b[1000];
int ans;
int f;
void dfs(int x,int y,int step)
{
    a[step]=x;
    b[step]=y;
    if(step==s)
    {
        f=1;
        return ;
    }
    for(int i=0;i<8;i++)
    {
        int nx=x+dx[i];
        int ny=y+dy[i];
        if(nx>=1&&ny>=1&&nx<=n&&ny<=m&&mp[nx][ny]==0&&f==0)
        {
            mp[nx][ny]=1;
            dfs(nx,ny,step+1);
            mp[nx][ny]=0;
        }
    }
}
int main()
{
    int t;
    cin>>t;
    int k=0;
    while(t--)
    {
        cin>>n>>m;
        memset(mp,0,sizeof(mp));
        s=n*m;
        mp[1][1]=1;
        f=0;
        dfs(1,1,1);
        if(f==0)
        {
            cout<<"Scenario #"<<++k<<":\nimpossible\n";
        }
        else
        {
            cout<<"Scenario #"<<++k<<":"<<endl;
            for(int i=1;i<=s;i++)
            {
                printf("%c%d",b[i]+'A'-1,a[i]);
            }
            cout<<endl;
        }
        if(t!=0)cout<<endl;
    }
    return 0;
}
</span>
/*
F:\temp\16139552.54569\Main.cc:2: error: stray '#' in program
F:\temp\16139552.54569\Main.cc:2: error: expected unqualified-id before '<' token
In file included from cstdio:44,
                 from F:\temp\16139552.54569\Main.cc:3:
cstddef:51: error: '::ptrdiff_t' has not been declared
F:\temp\16139552.54569\Main.cc: In function 'int main()':
F:\temp\16139552.54569\Main.cc:41: error: 'cin' was not declared in this scope
F:\temp\16139552.54569\Main.cc:53: error: 'cout' was not declared in this scope
F:\temp\16139552.54569\Main.cc:57: error: 'cout' was not declared in this scope
F:\temp\16139552.54569\Main.cc:57: error: 'endl' was not declared in this scope
F:\temp\16139552.54569\Main.cc:64: error: 'cout' was not declared in this scope
F:\temp\16139552.54569\Main.cc:64: error: 'endl' was not declared in this scope
F:\temp\16139552.54569\Main.cc: At global scope:
F:\temp\16139552.54569\Main.cc:68: error: expected unqualified-id before '<' token
*/

Double click to view unformatted code.


Back to problem 1005