7.29总结

· · 闲话

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。

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;
}

这辈子不想写广搜了

\Huge Bye\sim