手写队列:RE
  • 板块P3395 路障
  • 楼主BIG_CUTE_BUG
  • 当前回复5
  • 已保存回复5
  • 发布时间2022/10/25 18:51
  • 上次更新2023/10/27 05:56:00
查看原帖
手写队列:RE
398983
BIG_CUTE_BUG楼主2022/10/25 18:51

link

#include<bits/stdc++.h>
using namespace std;
int t,n;

struct node{
    int x,y,t;
}lz[2050];
int nx[]={1,-1,0,0};
int ny[]={0,0,1,-1};
bool vis[1050][1050];
bool bfs()
{
    int head=1,tail=2;
    node q[2500]={};
//  int fa[2000];
    q[1]={1,1,0};
    vis[1][1]=1;
    while(head<tail)
    {
        node cs=q[head];
        head++;
        if(cs.x==n&&cs.y==n)return 1;
        vis[lz[cs.t].x][lz[cs.t].y]=1;
        for(int i=0;i<4;i++)
        {
            node ns={cs.x+nx[i],cs.y+ny[i],cs.t+1};
            if(ns.x<1||ns.y<1||ns.x>n||ns.y>n||vis[ns.x][ns.y])continue;
            vis[ns.x][ns.y]=1;
            q[tail]=ns;
            tail++;
        }
    }
    return 0;
}
int main(){
    scanf("%d",&t);
    while(t--)
    {
        memset(vis,0,sizeof(vis));
        memset(lz,0,sizeof(lz));
        scanf("%d",&n);
        for(int i=1;i<=n*2-2;i++)
            scanf("%d%d",&lz[i].x,&lz[i].y);
        if(bfs())puts("Yes");
        else puts("No");
    }
    return 0;
}
2022/10/25 18:51
加载中...