Submission #7576961


Source Code Expand

#include<iostream>
#include<queue>
using namespace std;
const int maxn=505;
int n,m; 
int a[maxn][maxn];
bool  b[maxn][maxn];
bool vis[maxn][maxn];
char c; 
int sx,sy,tx,ty;
queue<int>qx,qy;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
		{
			cin>>c;
			if(c=='s')sx=i,sy=j,a[i][j]=1;//起点 
			else if(c=='g')tx=i,ty=j,a[i][j]=1; //终点 
			else if(c=='.')a[i][j]=1;//通路 
			else if(c=='#')a[i][j]=2;//墙壁 
		} 
	qx.push(sx),qy.push(sy);
	vis[sx][sy]=1;
	while(!qx.empty())
	{
		int tmpx=qx.front(),tmpy=qy.front();
		qx.pop(),qy.pop(); 
		if(tmpy+1<=m&&a[tmpx][tmpy+1]==1&&!vis[tmpx][tmpy+1])
		{
			vis[tmpx][tmpy+1]=1;
			qx.push(tmpx),qy.push(tmpy+1);
		}
		if(tmpy-1>=1&&a[tmpx][tmpy-1]==1&&!vis[tmpx][tmpy-1])
		{
			vis[tmpx][tmpy-1]=1;
			qx.push(tmpx),qy.push(tmpy-1);
		}
		if(tmpx-1>=1&&a[tmpx-1][tmpy]==1&&!vis[tmpx-1][tmpy])
		{
			vis[tmpx-1][tmpy]=1;
			qx.push(tmpx-1),qy.push(tmpy);
		}
		if(tmpx+1<=n&&a[tmpx+1][tmpy]==1&&!vis[tmpx+1][tmpy])
		{
			vis[tmpx+1][tmpy]=1;
			qx.push(tmpx+1),qy.push(tmpy);
		}
	} 
	if(vis[tx][ty])printf("Yes");
	else printf("No");
	return 0;
 } 

Submission Info

Submission Time
Task A - 深さ優先探索
User luogu_bot5
Language C++ (GCC 5.4.1)
Score 0
Code Size 1197 Byte
Status CE

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:14:20: error: ‘scanf’ was not declared in this scope
  scanf("%d%d",&n,&m);
                    ^
./Main.cpp:51:29: error: ‘printf’ was not declared in this scope
  if(vis[tx][ty])printf("Yes");
                             ^
./Main.cpp:52:18: error: ‘printf’ was not declared in this scope
  else printf("No");
                  ^