ultimate_regular @ 2023-07-23 18:11:37
#include <bits/stdc++.h>
using namespace std;
int ans=0;
int ey,ex,fx,fy,sx,sy,n,m,t;
int mymap[105][105];
bool vis[105][105];
int _x[]={0,-1,0,1};
int _y[]={-1,0,1,0};
void dfs(int x,int y)
{
if(x==ex&&y==ey){
return ;
}
for(int i=0;i<4;i++){
int dx=x+_x[i];
int dy=y+_y[i];
if(dx>0&&dx<=n&&dy>0&&dy<=m&&vis[dx][dy]==0&&mymap[dx][dy]!=1)
{
vis[dx][dy]=1;
dfs(dx,dy);
vis[dx][dy]=0;
}
}
}
int main()
{
cin>>n>>m>>t;
cin>>sx>>sy>>ex>>ey;
while(t--){
int ax,ay;
cin>>ax>>ay;
mymap[ax][ay]=1;
}
vis[sx][sy]=1;
dfs(sx,sy);
if(dfs)
cout<<"Yes";
else
cout<<"No";
return 0;
}
by bowenzuo @ 2023-07-23 18:16:22
应该是
dx>=0&&dx<=n&&dy>=0&&dy<=m
吧qwq(不确定
by bowenzuo @ 2023-07-23 18:19:21
if(dx>=0&&dx<=n&&dy>=0&&dy<=m&&vis[dx][dy]==0&&mymap[dx][dy]!=1)
{
vis[dx][dy]=1;
dfs(dx,dy);
vis[dx][dy]=0;
}
你这是dfs了但又没完全dfs
我dfs是这样写的
void dfs(int x,int y)
{
for(int i=0;i<4;i++)
{
dx=x+gox[i];
dy=y+goy[i];
if(dx>=0&&dx<n&&dy>=0&&dy<m&&f[dx][dy]!=true)
{
f[dx][dy]=true;
if(dx==n-1&&dy==m-1)
{
printf("Yes");
pd=true;
break;
}
else
{
dfs(dx,dy);
}
}
}
}
借鉴一下吧qwq
by bowenzuo @ 2023-07-23 18:22:07
欸完了我看错了qwq
by bowenzuo @ 2023-07-23 18:23:47
那就应该是dfs的条件(我第一次说的写错了吧
by ultimate_regular @ 2023-07-23 18:34:06
@bowenzuo 感谢感谢我好弱
by __pipi__ @ 2023-07-23 18:34:36
你这终点判断不包熟阿