Hayden124 @ 2023-07-15 22:13:33
我在c++中运行样例是对的,可是全是wa(悲),试了几次都是正确的,不知道哪里错了,本人十分急!!!
#include<bits/stdc++.h>
using namespace std;
int moves[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
int n,m;
int v[200][200];
char a[200][200];
void dfs(int x,int y)
{
for(int i=0;i<4;i++)
{
int nx=x+moves[i][0];
int ny=y+moves[i][1];
if(a[nx][ny]!='#'&&nx<=n&&ny<=m&&nx>=0&&ny>=0&&v[nx][ny]==0)
{
v[nx][ny]=1;
dfs(nx,ny);
}
}
}
int main()
{
cin>>n>>m;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cin>>a[i][j];
v[i][j]=0;
}
}
if(a[0][0]=='#'||a[n][m]=='#')
{
cout<<"NO"<<endl;
}
v[1][1]=1;
dfs(1,1);
if(v[n][m]==1) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return 0;
}
by lovely_fcukh @ 2023-07-15 22:24:17
6,你有一下几个错误:
帮你改好了
#include<bits/stdc++.h>
using namespace std;
int moves[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
int n,m;
int v[200][200];
char a[200][200];
void dfs(int x,int y)
{
for(int i=0;i<4;i++)
{
int nx=x+moves[i][0];
int ny=y+moves[i][1];
if(a[nx][ny]!='#'&&nx<n&&ny<m&&nx>=0&&ny>=0&&v[nx][ny]==0)
{
v[nx][ny]=1;
dfs(nx,ny);
}
}
}
int main()
{
cin>>n>>m;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cin>>a[i][j];
v[i][j]=0;
}
}
if(a[0][0]=='#'||a[n-1][m-1]=='#')
{
cout<<"No"<<endl;
}
v[0][0]=1;
dfs(0,0);
if(v[n-1][m-1]==1) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;
}
by Hayden124 @ 2023-07-16 07:39:13
谢谢大佬!!!
by Hayden124 @ 2023-07-16 07:48:27
YES,NO和Yes,No那里太坑了!!qwq