题目:(来自码酷)
|
这个思路是:
先把周围的部分变成3,然后递归,
如果这个点以前走过或者到边框或者是墙
就返回
否则
这个点变为2,变成可以走
然后试一下周围的能不能走。
难度:普及组
知识点:递归
代码如下:
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
//ifstream cin(".in");
//ofstream cout(".out");
int a[99][99];//数组不要定大,这样就行了!
void f(int y,int x)
{
if(a[y][x]!=0)return ;//如果这个不是可以走(如果这个点以前走过或者到边框或者是墙),就返回
a[y][x]=2;//标记走过
f(y,x+1);
f(y,x-1);
f(y+1,x);
f(y-1,x);//四周
}
int main()
{
int i,j,n,m;
cin>>n>>m;
for(i=0;i<=n+1;i++)
for(j=0;j<=m+1;j++)
a[i][j]=3;//边框
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
cin>>a[i][j];//输入
int q,w,e,r;
cin>>q>>w>>e>>r;
f(q,w);
if(a[e][r]==2)
cout<<"OK!"<<endl;//如果这个走过,就输出ok,要不然,就输出no
else
cout<<"NO!"<<endl;
//system ("pause");记住!
return 0;
}
//大家不要抄我的代码去提交,那样没有意思,还是骗自己!
//希望大家喜欢我的程序! =