C. Arrow Path

原题链接

题解

1.由于没有指向外面的箭头,所以 \((1,1)\ (1,2)\) 都是 >
2.每次移动两步,所以落点一定是距离原点曼哈顿距离为偶数的点,所以中转点一定是曼哈顿距离为奇数的点,所以枚举所有曼哈顿距离为奇数的点(不包括终点),只要其没有连续出现<,一定能过去

code

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        string s[2];
        cin>>s[0]>>s[1];
        int floor=1,flag=1;
        for(int i=2;i<n;i++)
        {
            if(s[floor][i]=='<'&&s[(floor+1)%2][i-1]=='<'&&!(floor==1&&i==n-1))
            {
                flag=0;
                break;
            }
            floor=(floor+1)%2;
        }
        puts(flag?"YES":"NO");
    }
    return 0;
}

posted @ 2024-03-27 21:59  纯粹的  阅读(132)  评论(0)    收藏  举报