T1 T638280 兜兜转转还是你
赛时代码:
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N=114514;
int main(){
ios::sync_with_stdio(0);
cout<<"Yes";
return 0;
}骗分:D
一道广搜题
思路:
进行 四次 bfs。
-
bfs ( 1 ) : 从位置 出发,如果能搜到1 , 2 , 3 , 4就输出
YES -
bfs ( 2 ) : 从位置 出发,如果能搜到 1 , 2 , 3 , 4 就输出
YES -
bfs ( 3 ) : 从位置 出发, 如果能搜到 1 , 2 , 3 , 4 就输出
YES -
bfs ( 4 ) : 从位置 出发,如果能搜到 1 , 2 , 3 ,4 就输出
YES
Code:
#include<bits/stdc++.h>
#define int long long
using namespace std;
struct node
{
int x,y;
};
int dx[4]={0,0,-1,1};
int dy[4]={1,-1,0,0};
int n,m,fx,fy;
vector<bool> vis[100010];
char c;
void bfs(int x,int y)
{
queue<node> q;
for(int i=0;i<4;i++)
{
node k;
k.x=x+dx[i];
k.y=y+dy[i];
if(k.x>=1 && k.x<=n && k.y>=1 && k.y<=m && !vis[k.x][k.y])
{
vis[k.x][k.y]=true;
while(!q.empty())
{
q.pop();
}
q.push(k);
while(!q.empty())
{
node f=q.front();
q.pop();
for(int j=0;j<4;j++)
{
node nf;
nf.x=f.x+dx[j];
nf.y=f.y+dy[j];
if(nf.x>=1 && nf.x<=n && nf.y>=1 && nf.y<=m && !vis[nf.x][nf.y])
{
vis[nf.x][nf.y]=true;
if((nf.x==x+1 && nf.y==y) || (nf.x==x-1 && nf.y==y) || (nf.x==x && nf.y==y+1) || (nf.x==x && nf.y==y-1))
{
cout<<"Yes";
return ;
}
q.push(nf);
}
}
}
}
}
cout<<"No";
}
signed main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
vis[i].push_back(false);
for(int j=1;j<=m;j++)
{
cin>>c;
if(c=='#')
{
vis[i].push_back(true);
}
else if(c=='S')
{
fx=i;
fy=j;
vis[i].push_back(true);
}
else
{
vis[i].push_back(false);
}
}
}
bfs(fx,fy);
return 0;
}这辈子不想写广搜了