C. 思维 Pipes Codeforces Round #590 (Div. 3)

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/weixin_43880084/article/details/101883043

Codeforces Round #590 (Div. 3)
在这里插入图片描述

在这里插入图片描述

Example
inputCopy
6
7
2323216
1615124
1
3
4
2
13
24
2
12
34
3
536
345
2
46
54
outputCopy
YES
YES
YES
NO
YES
NO
Note
The first query from the example is described in the problem statement.


  • 很显然的是直的管只能横着放(无法衔接上下移动的方向接过来的管子)
  • 对于拐角管 如果之前是横着运动的 那么现在就得上移或者下移
  • 如果之前就是上下移动那么现在只可横着移动
  • now所在类 y所在行 dir前面的方向
#include<bits/stdc++.h>
using namespace std;
char s[2][200010];
int main()
{
	int tt;scanf("%d",&tt);
	while(tt--)
	{
		int n;scanf("%d",&n);
		scanf("%s%s",s[0],s[1]);
		int now=0,y=0,dir=0,f=0;
		while(now<n)
		{
			
			if(dir==0)//之前横 
			{
				if(s[y][now]=='1'||s[y][now]=='2')
				{
					now++;
				}else
			    {
			    	y=!y;
					dir=1; 
				}
			}else //之前竖着 
			{
				if(s[y][now]=='2'||s[y][now]=='1')
				{
					f=1;
					 break;
				}else 
				{
					dir=0;
					now++;
				}
			} 
		
		} 
	
		if(f||y==0)  puts("NO");
		else puts("YES");
	} 
}

猜你喜欢

转载自blog.csdn.net/weixin_43880084/article/details/101883043