每日一题(呜呜呜补)

 

 

 题目大意:中文自己看。

思路:每次dfs,定义4个参数,分别是下一个走到的点x,y和走到这个点的方向dirx,diry。

然后每次dfs走到直管的时候方向不变,走到L型管的时候如果走到当前点的方向是向左(向右)那么方向就应该为向上(向下),如果是向上(向下),那么方向就应该为向左(向右)。每次

dfs如果走到当前点就标记退出即可。

其实思路还是挺简单的,就是细节问题有很多地方需要处理,比如点的越界或者st数组的初始化以及回溯,应该做多了就好了吧(wwww卡在回溯卡了n小时)

/**
*  ┏┓   ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃       ┃
* ┃   ━   ┃ ++ + + +
*  ████━████+
*  ◥██◤ ◥██◤ +
* ┃   ┻   ┃
* ┃       ┃ + +
* ┗━┓   ┏━┛
*   ┃   ┃ + + + +Code is far away from  
*   ┃   ┃ + bug with the animal protecting
*   ┃    ┗━━━┓ 神兽保佑,代码无bug 
*   ┃  	    ┣┓
*    ┃        ┏┛
*     ┗┓┓┏━┳┓┏┛ + + + +
*    ┃┫┫ ┃┫┫
*    ┗┻┛ ┗┻┛+ + + +
*/

#include<cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include<vector>
#include<queue>
#include<map>
#define ll long long 
using namespace std;

const int N=100000+10000;
int n ,m,h,p=0;
char  s[5][N];
bool st[5][N];
int X,Y;

void dfs(int dirx,int diry,int x,int y)//上一次的方向和现在走到的点
{
    if(p)return ;
      if(x==4){
        if(y==Y&&dirx==1&&diry==0) p=1;
        return ;
    }

    if(x<2||y<1||y>n||x>=4)return ;//走到第一个点或者第4个点
  
    if(st[x][y])return ;//已经走过了
    st[x][y]=true;

    if(s[x][y]=='I')//为直的
    {  
        dfs(dirx,diry,x+dirx,y+diry);
    }
    else if(s[x][y]=='L' ){
        if(diry==0)//向下或者向上
        {
            dirx=0,diry=-1;
            dfs(dirx,diry,x+dirx,y+diry); //向左 


            dirx=0,diry=1;
            dfs(dirx,diry,x+dirx,y+diry);

            //向右           
        }
        else if(dirx==0)//向左或者向右
        {
            dirx=1,diry=0;
            dfs(dirx,diry,x+dirx,y+diry); //向下 


            dirx=-1,diry=0;
            dfs(dirx,diry,x+dirx,y+diry);

            //向上
        }
    }
            st[x][y]=false;
}   

int main()
{
	int t ;
    cin>>t;
    while(t--)
    {
        p=0;
        cin>>n>>X>>Y;
        for(int i =2;i<=4;i++)
        for(int j =1;j<=n;j++)
        st[i][j]=false;
        
        for(int i=2;i<=3;i++)
        cin>>s[i]+1;

        dfs(1,0,2,X);
        if(p) cout<<"YES\n";
        else cout<<"NO\n";
    }
	return 0;
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值