Untitled
unknown
plain_text
2 years ago
906 B
9
Indexable
#include<iostream>
using namespace std;
char arr[16][16];
int dx[4]={-1,0,1,0};
int dy[4]={0,1,0,-1};
int dichuyen(int r, int c)
{
int map[16][16]={1};
int curX;
int curY;
if(map[curX][curY]==3) return true;
bool res=false;
for(int i=0; i<4;i++)
{
curX= r+ dx[i];
curY= c+ dx[i];
if( curX>=0 && curX<16 && curY>=0 && curY<16 && map[curX][curY]!=1)
{
res |= dichuyen(curX,curY);
}
}
return res;
}
int main()
{
freopen("text.txt","r",stdin);
for(int tc=1; tc<11; tc++)
{
int sx=0;
int sy=0;
for(int i=0; i<16;i++)
{
for(int j=0; j<16;j++)
{
cin>>arr[i][j];
arr[i][j]=arr[i][j]-'0';
if(arr[i][j]==2)
{
sx=i;
sy=j;
}
}
}
bool ans=dichuyen(sx,sy);
int dem=0;
if(ans)
{
dem=1;
}
else
{
dem=0;
}
cout<<"#"<<tc<<" "<<dem<<endl;
}
return 0;
}
Editor is loading...