系列文章目录
1.题目
迷宫是一个n*m的矩阵,玩家需要迷宫入口(坐标1,1)出发,寻找路径走到出口(n,m)。
请判断玩家能否从迷宫中走出。
输入格式
第一行两个整数n和m,代表n行m列。(1<=n,m<=10)
下面n行每行m个字符,0代表可以通行,1代表不可以通行。
输出格式
如果能从迷宫走出,输出yes,否则输出no。
输入样例
8 8
00100010
00100010
00001100
01110000
00010000
01000100
01110110
00001000
输出样例
yes
提示
样例数据即为图片迷宫
2.AC代码
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
using namespace std;
char a[15][15];
int book[15][15];//v访问
int dx[4]={-1,1,0,0};
int dy[4]={0,0,-1,1};
int main()
{
int n1,n2,tx,ty,flag=0,n,m;
cin>>n1>>n2;
for(int i=1;i<=n1;i++)
{
for(int j=1;j<=n2;j++)
{
cin>>a[i][j];
}
}
//cin>>n>>m;
///存可以走的坐标,可走就是可存
queue<int>x;
queue<int>y;
x.push(1);
y.push(1);///起点入队
///选方向--->做判断----->写好出口
//cout<<tx<<"1"<<ty<<endl;
while(!x.empty())///empty,空就返回1;
{//cout<<tx<<"12"<<ty<<endl;
for(int i=0;i<4;i++)
//左,右,下 ,上
{///cout<<tx<<"3"<<ty<<endl;
if( x.front()==n1&&y.front()==n2)//队头元素
{ flag=1;
break;
}///出口,有出口啦!
tx= x.front()+dx[i];
ty=y.front()+dy[i];
if(tx>=1&&tx<=n1&&ty<=n2&&ty>=1&&a[tx][ty]!='1'&&book[tx][ty]==0)
{
book[tx][ty]=1;
// cout<<tx<<ty<<endl;
x.push(tx);
y.push(ty);
}
}
x.pop();
y.pop();
}
///四个方向都走完了,才遍历下一项,就是tx,ty,滚出队列,下一点来四个方向,
///对每个点四个方向就遍历所有点了,至于有没有重复,交给book【】标记数组判断
///就好了,做好你的遍历就行了
//cout << "Hello world!" << endl;
if(flag==1)
cout<<"yes"<<'\n';
else
cout<<"no"<<'\n';
return 0;
}
总结
提示:这里对文章进行总结:
例如:以上就是今天要讲的内容,本文仅仅简单介绍了pandas的使用,而pandas提供了大量能使我们快速便捷地处理数据的函数和方法。
用队列记录。。。。。