描述:
有一个房间,房间里有一个人P,房间是规格为 n*n的方格,房子内某些位置上有箱子B,有些位置上有障碍物,人处于某一位置,可以选择向某方向前进,但要保证面对的不是墙、障碍物,若面对的是墙或障碍物则无法前进,若人面对箱子但箱子的前面为障碍物或者墙或者箱子,也不能前进,若为箱子并且箱子所面对的不是墙,不是障碍物也不是箱子,即为空格,则可以推动箱子,即人和箱子分别向这个方向移动一个格子。
输入:
房间的规格,一个正整数 n(2<=n<=100),占一行,代表矩阵的大小;输入方形矩阵n行n列,由0、1和2组成(其中0代表空地,1代表箱子,2代表障碍物),即房子的地图,输入一对数据row,col(第row行,第col列),表示人所在的位置坐标(保证人所在的位置为空地),以空格隔开,占一行;输入一个整数2,表示向右方向前进(0,1,2,3分别为向左下右上前进)。
输出:
"1"表示可以向该方向前进;
"0"表示不能向该方向前进;
输出占一行;
输入样例:
4 0 0 0 0 0 1 1 0 0 0 1 0 0 2 0 0 2 1 2
输出样例:
1
#include<iostream>
using namespace std;
int main()
{
int n,a,b,row,col,e;
cin>>n;
int A[n][n];
for(a=0;a<n;a++)
{
for(b=0;b<n;b++)
{
cin>>A[a][b];
}
}
cin>>row>>col;
cin>>e;
if(e==0)
{
if(col-1<0)
{
cout<<"0";
}
else
{
if(A[row][col-1]==0)
{
cout<<"1";
}
else if(A[row][col-1]==2)
{
cout<<"0";
}
else
{
if(col-2<0)
{
cout<<"0";
}
else if(A[row][col-2]==0)
{
cout<<"1";
}
else
{
cout<<"0";
}
}
}
}
else if(e==1)
{
if(row+1>n-1)
{
cout<<"0";
}
else
{
if(A[row+1][col]==0)
{
cout<<"1";
}
else if(A[row+1][col]==2)
{
cout<<"0";
}
else
{
if(row+2>n-1)
{
cout<<"0";
}
else if(A[row+2][col]==0)
{
cout<<"1";
}
else
{
cout<<"0";
}
}
}
}
else if(e==2)
{
if(col+1>n-1)
{
cout<<"0";
}
else
{
if(A[row][col+1]==0)
{
cout<<"1";
}
else if(A[row][col+1]==2)
{
cout<<"0";
}
else
{
if(col+2>n-1)
{
cout<<"0";
}
else if(A[row][col+2]==0)
{
cout<<"1";
}
else
{
cout<<"0";
}
}
}
}
else
{
if(col-1<0)
{
cout<<"0";
}
else
{
if(A[row-1][col]==0)
{
cout<<"1";
}
else if(A[row-1][col]==2)
{
cout<<"0";
}
else
{
if(row-2<0)
{
cout<<"0";
}
else if(A[row-2][col]==0)
{
cout<<"1";
}
else
{
cout<<"0";
}
}
}
}
}